Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BenchmarkDotNet fails to build auto-generated boilerplate for a project using Microsoft.NET.Sdk #1758

Closed
fanasere opened this issue Jul 29, 2021 · 2 comments

Comments

@fanasere
Copy link

I have a benchmark project which csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk;Microsoft.Build.CentralPackageVersions/2.0.79"> <PropertyGroup> <RootNamespace>ExampleNameSpace</RootNamespace> <AssemblyName>$(RootNamespace)</AssemblyName> <OutputType>Exe</OutputType> <TargetFrameworks>net5.0</TargetFrameworks> </PropertyGroup> <ItemGroup> <PackageReference Include="BenchmarkDotNet" /> </ItemGroup> <ItemGroup> </Project>
this project is part of a solution that has a Directory.Build.props file that contains configuration:
net462;netstandard2.0;net5.0

when I build the project using this command:
dotnet run -c release --framework net5.0
I get errors:
error NU1201: Project is not compatible with netstandard2.0 Project supports: net5.0
error NU1201: Project is not compatible with net462 Project supports: net5.0
when BDN tries to restore the project he generated.

when I go to the csproj the BDN generated, I can see that he generated it with configuration:
<TargetFramework>net5.0</TargetFramework> instead of <TargetFrameworks>net5.0</TargetFrameworks>
notice the difference between the two is the missing 's'.
when I add the missing s, and run the bat file containing the commands the BDN tried to run everything works fine.
any suggestions how I can solve this problem?

versions of nugets I'm using:
Microsoft.NET.Test.Sdk: 16.9.1
BenchmarkDotNet: 0.13.0

@timcassell
Copy link
Collaborator

timcassell commented Jul 29, 2021

To run .Net Framework benchmarks, you must build the project with a .Net Framework version dotnet run -c Release -f net462. Then BDN will build the .Net Core/5.0+ apps if you tell it to do so --runtimes net50 net462.

[Edit] I reread your issue, and it looks like I misunderstood. It seems you're only trying to run .Net 5.0 benchmarks, not Framework. I'm not familiar with Directory.Build.props files.

@YegorStepanov
Copy link
Contributor

Use it for proper formatting.

    ```xml
    ```
<Project Sdk="Microsoft.NET.Sdk;Microsoft.Build.CentralPackageVersions/2.0.79">
    <PropertyGroup>
        <RootNamespace>ExampleNameSpace</RootNamespace>
        <AssemblyName>$(RootNamespace)</AssemblyName>
        <OutputType>Exe</OutputType>
        <TargetFrameworks>net5.0</TargetFrameworks>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="BenchmarkDotNet" />
    </ItemGroup>
    <ItemGroup>
</Project>



docs:
Directory.Build.props adds the xml property if it's not contained in .csproj.

So, your generated project looks like:

<PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <TargetFrameworks>net462;netstandard2.0;net5.0</TargetFrameworks>
</PropertyGroup>

#1403 will solve this issue.


Workaround:

You can add an empty Directory.Build.props:

- solution/Directory.Build.props
- solution/src/project1.csproj
- solution/benchmarks/Directory.Build.props (empty; it overrides the solution's Directory.Build.props)
- solution/benchmarks/benchmarkProject.csproj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants