dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.38k stars 10k forks source link

Blazor Wasm App publish is failing with '--self-contained false --runtime linux-arm' on missing DotNetJsVersion #39284

Closed Reveon closed 10 months ago

Reveon commented 2 years ago

Describe the bug

dotnet publish of a new Blazor Wasm app with parameters --self-contained false --runtime linux-arm is failing because of missing DotNetJsVersion in ComputeBlazorPublishAssets task

The only reference that I could find for DotNetJsVersion is in this PR dotnet/sdk#21919 so maybe there is some connection to the error I am getting

I am using the latest version of Visual Studio (17.0.4) and .NET (6.0.101)

To Reproduce

1) Create new Blazor Wasm project in Visual Studio with default settings

obrazek

2) Add <PublishTrimmed>false</PublishTrimmed> to csproj to avoid error NETSDK1102 3) run dotnet publish --self-contained false --configuration debug --runtime linux-arm

Exceptions (if any)

C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(412,5): error MSB4044: The "ComputeBlazorPublishAssets" task was not given a value for the required parameter "DotNetJsVersion". [C:\Source\Projects\BlazorPublishIssue\BlazorPublishIssue.csproj]

Further technical details

Visual Studio 17.0.4

dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.101 Commit: ef49f6213a

Runtime Environment: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.101\

Host (useful for support): Version: 6.0.1 Commit: 3a25a7f1cc

.NET SDKs installed: 3.1.415 [C:\Program Files\dotnet\sdk] 5.0.401 [C:\Program Files\dotnet\sdk] 5.0.403 [C:\Program Files\dotnet\sdk] 6.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

pranavkm commented 2 years ago

BlazorWASM apps target the browser-wasm runtime and are always self-contained (the browser does not carry a runtime). Targeting a linux platform doesn't really make sense for it either.

Reveon commented 2 years ago

@pranavkm I get the same error also for the server project (when I create Asp.Net hosted Blazor app)

obrazek

obrazek

pranavkm commented 2 years ago

I guess the Blazor SDK has to mark SelfContained as a private property. You have a couple of options to resolve this:

a) You can avoid specifying --self-contained false as a publish option since it's false by default for the hosted app. b) You could modify the wasm app to ignore the value of SelfContained specified from the CLI:

- <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
+ <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly" TreatAsLocalProperty="SelfContained">

  <PropertyGroup>
+    <SelfContained>true</SelfContained>
  </PropertyGroup>
Reveon commented 2 years ago

the first one gives me this warning (but it builds anyway) warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used.

but the other one works perfectly (also the publish size is much smaller then for the first option). Thank you!

ghost commented 2 years ago

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

silentdevnull commented 1 year ago

Good Morning,

Does anyone have this working? I can publish to folder in Rider and everything works fine. If I do it from a build script on linux I receive the same error about DotNetJsVersion.

When I publish to folder in Rider I have self contained set to true.

Any help is appreciated!!!!

Thank you

KhoaDQ commented 1 year ago

I guess the Blazor SDK has to mark SelfContained as a private property. You have a couple of options to resolve this:

a) You can avoid specifying --self-contained false as a publish option since it's false by default for the hosted app. b) You could modify the wasm app to ignore the value of SelfContained specified from the CLI:

- <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
+ <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly" TreatAsLocalProperty="SelfContained">

  <PropertyGroup>
+    <SelfContained>true</SelfContained>
  </PropertyGroup>

I solved it, thanks

mythrz commented 1 year ago

Additional Information (related to Docker/container):

Using the above suggestion does not work for me with built-in container support. https://devblogs.microsoft.com/dotnet/announcing-builtin-container-support-for-the-dotnet-sdk/

The project is a .NET 7 Blazor Web Assembly (HTTPS is the only check) dotnet publish --os linux --arch x64 -c Release -p:PublishProfile=DefaultContainer

Steps to reproduce. Attempt 1: This does not work! see attempt 2!

NOTE: you can skip dotnet add package Microsoft.NET.Build.Containers now, since it is included in the SDK

-- -- -- // // -- -- --

Steps to reproduce. Attempt 2: This is now working in the beginning but with modifications to the code, it can stop the left-menu from working properly!

RUN dotnet restore BlazorHelloWorld.csproj COPY . . RUN dotnet build -c Release -o /app/build

FROM build AS publish RUN dotnet publish -c Release -o /app/publish

FROM nginx:alpine AS final WORKDIR /usr/share/nginx/html COPY --from=publish /app/publish/wwwroot . COPY nginx.conf /etc/nginx/nginx.conf


- open a terminal and navigate to the path these files are located
- run: docker build -t blazorhelloworld .
- run: docker run --name blazorhelloworld -d -p 7266:8080 blazorhelloworld
- open the browser (7266). It works.

**Note**: When debugging with VS it works fine. IF running from the container the menu does not work, start all over again from scratch! There are some kind of temporary files that cause the menu to stop working. I have failed to find which ones!! 
https://chrissainty.com/containerising-blazor-applications-with-docker-containerising-a-blazor-webassembly-app/
ghost commented 1 year ago

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

mkArtakMSFT commented 10 months ago

We believe this is addressed already in 8.0.