TheAngryByrd / MiniScaffold

F# Template for creating and publishing libraries targeting .NET 6.0 `net6.0` or console apps .NET 6.0 `net6.0`.
https://www.jimmybyrd.me/MiniScaffold/
MIT License
267 stars 31 forks source link

Executing test project with `dotnet run -p` fails unless `--framework` option is passed to dotnet run #239

Closed rmunn closed 3 years ago

rmunn commented 3 years ago

Describe the bug If I create a new project from the MiniScaffold template, then try to run the Expecto unit tests with dotnet run -p tests/Foo.Tests/Foo.Tests.fsproj, I get the error "Unable to run your project. Your project targets multiple frameworks. Specify which framework to run using '--framework'."

Editing Foo.Tests.fsproj and changing <TargetFrameworks>net5.0</TargetFrameworks> to <TargetFramework>net5.0</TargetFramework> fixes the issue, suggesting that https://github.com/dotnet/sdk/issues/8676 is the root cause.

To Reproduce Steps to reproduce the behavior:

  1. dotnet new mini-scaffold -n Foo -o Foo ; cd Foo
  2. Run ./build.sh once to restore packages (it fails on the F# Analyzers step, but that's an unrelated issue)
  3. Run dotnet run -p tests/Foo.Tests/Foo.Tests.fsproj. Fails.
  4. Run dotnet run -p tests/Foo.Tests/Foo.Tests.fsproj --framework net5.0. Succeeds.

Expected behavior dotnet run -p tests/Foo.Tests/Foo.Tests.fsproj should succeed without specifying the --framework option, since there's only one targeted framework in the project.

Desktop (please complete the following information):

Additional context I initially noticed this when I tried to run the tests using Ionide's "run" tool on the test project. That is, this one:

image

The DotnetTest step in build.fsx succeeded even with TargetFrameworks in the .fsproj file, so I wouldn't have noticed this issue if the F# Analyzers step hadn't failed. But when F# Analyzers failed, instead of commenting out the ==> "FSharpAnalyzers" step, I loaded the project into VS Code and tried running tests with Ionide's "run" button, which calls dotnet run -p (project file). That's how I discovered this issue.

So it's a relatively minor issue, and it's easily fixed by changing TargetFrameworks to TargetFramework in all the .fsproj files. But then it may not be immediately clear to .NET newbies how to compile against multiple frameworks if they want to. So this might turn out to be a "won't fix" because the drawbacks of making that change might outweigh the benefits.

TheAngryByrd commented 3 years ago

I'm slightly torn on which way to go but I think since we're only targeting net5.0 now it might make sense to to use the singular variant over the plural.