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

dotnet run won't work by default for the new Blazor Web template #49071

Closed
SteveSandersonMS opened this issue Jun 28, 2023 · 3 comments
Closed
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-full-stack-web-ui Full stack web UI with Blazor
Milestone

Comments

@SteveSandersonMS
Copy link
Member

As it stands, people will have to do dotnet run -f net8.0 otherwise they'll get:

Unable to run your project
Your project targets multiple frameworks. Specify which framework to run using '--framework'.

There's no equivalent problem for launching from Visual Studio, though TBH I'm not even sure how VS decides which framework to use. I suspect we are not going to want dotnet run to become difficult, nor do we want to write the name of a specific TFM in all the tutorials and docs which will then get obsoleted with .NET 9.

Is there a mechanism (e.g., in launchSettings.json) that will configure dotnet run to pick a particular TFM by default? Or do we need to add something to the SDK to tell dotnet run that it should always ignore the -browser TFM?

@SteveSandersonMS SteveSandersonMS added area-blazor Includes: Blazor, Razor Components feature-full-stack-web-ui Full stack web UI with Blazor labels Jun 28, 2023
@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Jun 28, 2023
@danroth27
Copy link
Member

@baronfel Is there a way to make net8.0 the default target framework to run when the project is multi targeted for both net8.0 and net8.0-browser?

@baronfel
Copy link
Member

Not currently, no. Run relies on doing an evaluation of a project and getting the RunCommand and RunArguments properties from that evaluation, and the SDK targets only set those when a specific TargetFramework is known.

There are a few options here:

  • Blazor targets could do like MAUI does and set these values to call another target that enforces the behaviors you want to have. See How to make dotnet run invoke an MSBuild target? sdk#31253 for more context here
  • We in the SDK could establish some convention in the run command - when we do the evaluation, if no Framework option was specified via CLI args and the project to be run has multiple TFMs, try again, this time selecting the Nth TFM (likely first).
    • I don't like this, this is just a strawman. I think it would be too fragile in practice.
  • The run 'protocol' could grow another property used to determine what Framework to use by default, and Blazor projects/the Blazor SDK could set this for the run command to start reading
  • We could implement How to make dotnet run invoke an MSBuild target? sdk#31253 and make run delegate to a Run target that could be overridden, and you could do whatever logic you chose in that target.

There are likely more - I have a slight preference for expanding the 'run protocol' a bit more here instead of ejecting entirely. @dsplaisted can you see other options here?

@mkArtakMSFT mkArtakMSFT added this to the 8.0-preview7 milestone Jun 29, 2023
@javiercn
Copy link
Member

javiercn commented Jun 29, 2023

This is possible by doing this in the project

    <RunCommand Condition="'$(InnerRun)' == ''">dotnet</RunCommand>
    <RunArguments Condition="'$(InnerRun)' == ''">msbuild /t:Run /p:TargetFramework=net8.0 /p:InnerRun=true</RunArguments>

image

@ghost ghost locked as resolved and limited conversation to collaborators Aug 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-full-stack-web-ui Full stack web UI with Blazor
Projects
None yet
Development

No branches or pull requests

5 participants