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

StaticWebAssets.targets: Fix dotnet/runtime+preview7 builds #19578

Closed

Conversation

radical
Copy link
Member

@radical radical commented Aug 7, 2021

dotnet/runtime builds fail using preview7(6.0.100-preview.7.21379.14) with:

/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error : System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/radical/dev/r3/artifacts/obj/mono/BrowserDebugHost/Release/net6.0/StaticWebAssets.build.json'. [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) in System.Private.CoreLib.dll:token 0x60000d6+0x0 [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) in System.Private.CoreLib.dll:token 0x60000da+0x31 [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at System.IO.File.WriteAllBytes(String path, Byte[] bytes) in System.Private.CoreLib.dll:token 0x6005cce+0x2b [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at Microsoft.AspNetCore.Razor.Tasks.GenerateStaticWebAssetsManifest.PersistManifest(StaticWebAssetsManifest manifest) in Microsoft.NET.Sdk.Razor.Tasks.dll:token 0x600018a+0x3b [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at Microsoft.AspNetCore.Razor.Tasks.GenerateStaticWebAssetsManifest.Execute() in Microsoft.NET.Sdk.Razor.Tasks.dll:token 0x6000187+0xeb [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error : Could not find a part of the path '/Users/radical/dev/r3/artifacts/obj/mono/BrowserDebugHost/Release/net6.0/StaticWebAssets.build.json'. [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]

Specifically, the BrowserDebugHost project fails:

.../Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error : System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/radical/dev/r3/artifacts/obj/mono/BrowserDebugHost/Release/net6.0/StaticWebAssets.build.json'

And this is failing because it is building $(StaticWebAssetBuildManifestPath) using
$(BaseIntermediateOutputPath). But for mono builds, the intermediate
output paths are changed, in src/mono/Directory.Build.props.

But the targets are assuming that the constructed path:

<_StaticWebAssetsManifestBase>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework.ToLowerInvariant())\</_StaticWebAssetsManifestBase>

.. would have already been created. But since that gets changed for mono
builds, the path being used here never gets created. And so it fails
with:

System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/radical/dev/r3/artifacts/obj/mono/BrowserDebugHost/Release/net6.0/StaticWebAssets.build.json'

Note that other paths, like $(_StaticWebAssetsIntermediateOutputPath)
are built using $(IntermediateOutputPath), which correctly gets
created, so that, and others in the same targets file are not affected.

This change was added in:

commit 9ed247b28cba4501185dad4e546dc9c51e1c5711
Author: Javier Calvarro Nelson <jacalvar@microsoft.com>
Date:   Thu Jul 15 20:48:36 2021 +0200

    [ASP.NET Core] Static web assets improvements (#18871)

`dotnet/runtime` builds fail using preview7(`6.0.100-preview.7.21379.14`) with:

```
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error : System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/radical/dev/r3/artifacts/obj/mono/BrowserDebugHost/Release/net6.0/StaticWebAssets.build.json'. [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) in System.Private.CoreLib.dll:token 0x60000d6+0x0 [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) in System.Private.CoreLib.dll:token 0x60000da+0x31 [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at System.IO.File.WriteAllBytes(String path, Byte[] bytes) in System.Private.CoreLib.dll:token 0x6005cce+0x2b [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at Microsoft.AspNetCore.Razor.Tasks.GenerateStaticWebAssetsManifest.PersistManifest(StaticWebAssetsManifest manifest) in Microsoft.NET.Sdk.Razor.Tasks.dll:token 0x600018a+0x3b [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error :    at Microsoft.AspNetCore.Razor.Tasks.GenerateStaticWebAssetsManifest.Execute() in Microsoft.NET.Sdk.Razor.Tasks.dll:token 0x6000187+0xeb [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error : Could not find a part of the path '/Users/radical/dev/r3/artifacts/obj/mono/BrowserDebugHost/Release/net6.0/StaticWebAssets.build.json'. [/Users/radical/dev/r3/src/mono/wasm/debugger/BrowserDebugHost/BrowserDebugHost.csproj]
```

Specifically, the `BrowserDebugHost` project fails:

`.../Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(425,5): error : System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/radical/dev/r3/artifacts/obj/mono/BrowserDebugHost/Release/net6.0/StaticWebAssets.build.json'`

And this is failing because it is building `$(StaticWebAssetBuildManifestPath)` using
`$(BaseIntermediateOutputPath)`. But for mono builds, the intermediate
output paths are changed, in `src/mono/Directory.Build.props`.

But the targets are assuming that the constructed path:

`<_StaticWebAssetsManifestBase>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework.ToLowerInvariant())\</_StaticWebAssetsManifestBase>`

.. would have already been created. But since that gets changed for mono
builds, the path being used here never gets created. And so it fails
with:

`System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/radical/dev/r3/artifacts/obj/mono/BrowserDebugHost/Release/net6.0/StaticWebAssets.build.json'`

Note that other paths, like `$(_StaticWebAssetsIntermediateOutputPath)`
are built using `$(IntermediateOutputPath)`, which correctly gets
created, so that, and others in the same targets file are not affected.

This change was added in:
```
commit 9ed247b
Author: Javier Calvarro Nelson <jacalvar@microsoft.com>
Date:   Thu Jul 15 20:48:36 2021 +0200

    [ASP.NET Core] Static web assets improvements (dotnet#18871)
```
@javiercn
Copy link
Member

javiercn commented Aug 7, 2021

@radical thanks for submitting the fix and the detailed explanation.

I need to think a bit about it, the change that we did was intentional because using the intermediate output path didn't work in some cases that involved the rid, so I believe there will be one test that fails as a result, and I want to make sure we don't regress an actual customer scenario.

Would an alternative be to ensure that the directory is created?

The main issue is that the manifest is put in a place (obj\Debug\net6) as part of the build (there's no rid) and when publish happens it tries to read it from (obj\Debug\net6<>) as there is a rid defined for it. We always want the manifest to appear in (obj{Configuration}{targetframework})

@javiercn javiercn added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label Aug 7, 2021
@radical
Copy link
Member Author

radical commented Aug 7, 2021

Would an alternative be to ensure that the directory is created?

AFAIU, yeah. Could you also try to build dotnet/runtime with something like ./build.sh -os browser -arch wasm -c Release, with your fix for the sdk, to validate it?

@javiercn
Copy link
Member

javiercn commented Aug 7, 2021

@radical If you need to get unblocked right away, I suggest you set <StaticWebAssetsEnabled>false</StaticWebAssetsEnabled> and that'll disable the feature completely.

@radical
Copy link
Member Author

radical commented Aug 11, 2021

@javiercn can this be closed now?

@javiercn
Copy link
Member

I believe so

@dotnet dotnet locked and limited conversation to collaborators Aug 11, 2021
@radical radical closed this Aug 11, 2021
@radical radical deleted the p7-build-fix branch August 24, 2021 22:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch Area-NetSDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants