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

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

Closed
rmunn opened this issue May 25, 2021 · 1 comment · Fixed by #241

Comments

@rmunn
Copy link
Contributor

rmunn commented May 25, 2021

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 dotnet/sdk#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):

  • OS: Linux Mint 19.1 (based on Ubuntu 18.04)
  • Browser: irrelevant
  • .NET SDK: 5.0.203

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
Copy link
Owner

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.

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

Successfully merging a pull request may close this issue.

2 participants