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

Template has hardcoded netcoreapp3.0 TFM #1512

Closed
am11 opened this issue Aug 8, 2020 · 9 comments
Closed

Template has hardcoded netcoreapp3.0 TFM #1512

am11 opened this issue Aug 8, 2020 · 9 comments

Comments

@am11
Copy link
Member

am11 commented Aug 8, 2020

Using dotnet 5.0 preview 8, the template produces netcoreapp3.0 hardcoded csproj:

$ dotnet new --version
5.0.100-preview.8.20362.3

$ dotnet new --install BenchmarkDotNet.Templates::0.12.1
$ dotnet new benchmark --console-app -n MathBenchmarks
$ cd MathBenchmarks
$ head -3 MathBenchmarks.csproj

outputs:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>

running it with dotnet run gives:

It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.0.0' was not found.
  - The following frameworks were found:
      5.0.0-preview.8.20361.2 at [/Users/am11/.dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.0.0&arch=x64&rid=osx.10.14-x64

running after fixing csproj by hand, by replacing netcoreapp3.0 with net5.0, results in the following exception:

Unhandled exception. System.NotSupportedException: Unknown .NET Runtime
   at BenchmarkDotNet.Portability.RuntimeInformation.GetCurrentRuntime()
   at BenchmarkDotNet.Characteristics.Resolver.<>c__DisplayClass1_0`1.<Register>b__0(CharacteristicObject obj)
   at BenchmarkDotNet.Characteristics.Resolver.Resolve[T](CharacteristicObject obj, Characteristic`1 characteristic)
   at BenchmarkDotNet.Characteristics.CompositeResolver.Resolve[T](CharacteristicObject obj, Characteristic`1 characteristic)
   at BenchmarkDotNet.Characteristics.CharacteristicObject.ResolveValue[T](Characteristic`1 characteristic, IResolver resolver)
   at BenchmarkDotNet.Toolchains.ToolchainExtensions.GetToolchain(Job job, Descriptor descriptor)
   at BenchmarkDotNet.Toolchains.ToolchainExtensions.GetToolchain(BenchmarkCase benchmarkCase)
   at BenchmarkDotNet.Running.BenchmarkRunnerClean.<>c__DisplayClass12_0.<GetSupportedBenchmarks>b__2(BenchmarkCase benchmark)
   at System.Linq.Enumerable.WhereArrayIterator`1.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at BenchmarkDotNet.Running.BenchmarkRunnerClean.<>c__DisplayClass12_0.<GetSupportedBenchmarks>b__0(BenchmarkRunInfo info)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at BenchmarkDotNet.Running.BenchmarkRunnerClean.GetSupportedBenchmarks(BenchmarkRunInfo[] benchmarkRunInfos, ILogger logger, IResolver resolver)
   at BenchmarkDotNet.Running.BenchmarkRunnerClean.Run(BenchmarkRunInfo[] benchmarkRunInfos)
   at BenchmarkDotNet.Running.BenchmarkRunner.RunWithDirtyAssemblyResolveHelper(Type type, IConfig config)
   at BenchmarkDotNet.Running.BenchmarkRunner.<>c__DisplayClass0_0`1.<Run>b__0()
   at BenchmarkDotNet.Running.BenchmarkRunner.RunWithExceptionHandling(Func`1 run)
   at BenchmarkDotNet.Running.BenchmarkRunner.Run[T](IConfig config)
   at MathBenchmarks.Program.Main(String[] args) in /Users/am11/projects/MathBenchmarks/Program.cs:line 9

In addition to net5.0 support; ideally, BDN's template (like many other templates available on nuget) should use the latest TFM supported by executing dotnet process (3.1 or 5.0, instead of fixed 3.0).

@am11
Copy link
Member Author

am11 commented Aug 10, 2020

Some additional findings; the -f flag is ignored when --console-app is supplied:

$ dotnet new benchmark --console-app -n MathBenchmarks -f netcoreapp3.1 # or net5.0
# still produces csproj with TargetFramework set to netcoreapp3.0

# while the library project (without --console-app argument)
$ dotnet new benchmark -n MathBenchmarks -f netcoreapp3.1 # or net5.0
# produces csproj with the expected TargetFramework value

@adamsitnik
Copy link
Member

I just took a look at the templates and I agree that they should be updated and also simplified. I've marked the issue as up-for-grabs.

@LevYas
Copy link

LevYas commented Dec 11, 2020

I've just checked the .csproj file generated at \Source\Tests\Benchmarks\bin\Release\1c6b7b7c-c006-4660-9342-ea8aef01ff6f\BenchmarkDotNet.Autogenerated.csproj, looks like it's ok:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
    <ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
    <AssemblyTitle>1c6b7b7c-c006-4660-9342-ea8aef01ff6f</AssemblyTitle>
    <TargetFramework>netcoreapp5.0</TargetFramework>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <PlatformTarget>x64</PlatformTarget>
    <AssemblyName>1c6b7b7c-c006-4660-9342-ea8aef01ff6f</AssemblyName>
    <OutputType>Exe</OutputType>
    <OutputPath>bin\Release</OutputPath>
    <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <UseSharedCompilation>false</UseSharedCompilation>
    <CodeAnalysisRuleSet></CodeAnalysisRuleSet>
    
    <!-- we set LangVersion after  which might contain LangVersion copied from the benchmarks project -->
    <LangVersion Condition="'$(LangVersion)' == '' Or '$(LangVersion)' &lt; '7.3'">latest</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="1c6b7b7c-c006-4660-9342-ea8aef01ff6f.notcs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="<myproject>\Source\Tests\Benchmarks\Benchmarks.csproj" />
  </ItemGroup>
  
</Project>

Am I missing something or the issue is already solved?

@am11
Copy link
Member Author

am11 commented Dec 11, 2020

This issue is about benchmark dotnet template https://www.nuget.org/packages/BenchmarkDotNet.Templates/, which was last updated eight months ago. It still creates a new console project with netcoreapp3.0 with repro steps shown in the first post.

@am11
Copy link
Member Author

am11 commented Dec 11, 2020

@LevYas
Copy link

LevYas commented Dec 12, 2020

Got it, thank you. I'm new to BDN, I thought this template is used to generate that csproj I sent before.

@ExceptionCaught
Copy link
Contributor

hi @adamsitnik . I would like to contribute, can you please assign this to me. cheers. and Happy new year.

@adamsitnik
Copy link
Member

I would like to contribute, can you please assign this to me. cheers. and Happy new year.

@ExceptionCaught done, thank you!

adamsitnik pushed a commit that referenced this issue Jan 7, 2021
* update template framework variable to be passed from option with default 5.0

* refine the framework parameters.

* remove duplicate infomation.
@adamsitnik adamsitnik added this to the v0.13.0 milestone Jan 7, 2021
@adamsitnik
Copy link
Member

Fixed by #1630

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

No branches or pull requests

4 participants