Skip to content

Commit 83c0088

Browse files
committed
[wasm] Fix Publish for Blazorwasm projects on VS17
TL;dr `publish` fails on any blazorwasm project with VS17 A recent commit[1] moved initializing `$(_WasmIntermediateOutputPath)` from a target, to project level `PropertyGroup`. It is set as: `<_WasmIntermediateOutputPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'wasm'))</_WasmIntermediateOutputPath>` The `NormalizeDirectory` call converts this to a full path, presumably using the current directory. Because we are setting `$(_WasmIntermediateOutputPath)` at the project level, it gets evaluated during the evaluation phase. And the current directory doesn't seem to be set to the project directory at that point in VS. So, `$(_WasmIntermediateOutputPath)` gets a wrong path like: `C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\obj\Release\net6.0\wasm`. And then when actually publishing, it fails to create this directory with: `Unable to create directory "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\obj\Release\net6.0\wasm\". Access to the path 'C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\obj\Release\net6.0\wasm\' is denied.` Fix: Set the property in `_InitializeCommonProperties` *target*, at which point the current directory is correctly set. Note: - This doesn't seem to be reproducible outside VS - It happens only on `publish`, because that's when the wasm targets come into play. -- 1. ``` commit d574b03 Author: Ankit Jain <radical@gmail.com> Date: Mon Jul 19 01:02:01 2021 -0400 [wasm] Add support for using custom native libraries (dotnet#55797) ```
1 parent ec2d25c commit 83c0088

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/mono/wasm/build/WasmApp.Native.targets

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
<Target Name="WasmBuildNativeOnly" DependsOnTargets="$(WasmBuildNativeOnlyDependsOn)" Condition="'$(WasmBuildNative)' == 'true'" />
4040

4141
<Target Name="_PrepareForWasmBuildNativeOnly">
42-
<MakeDir Directories="$(_WasmIntermediateOutputPath)" />
43-
4442
<ItemGroup>
4543
<_WasmAssembliesInternal Remove="@(_WasmAssembliesInternal)" />
4644
<_WasmAssembliesInternal Include="@(WasmAssembliesToBundle->Distinct())" />

src/mono/wasm/build/WasmApp.targets

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@
8282
<!--<WasmStripAOTAssemblies Condition="'$(WasmStripAOTAssemblies)' == ''">$(RunAOTCompilation)</WasmStripAOTAssemblies>-->
8383
<WasmStripAOTAssemblies>false</WasmStripAOTAssemblies>
8484

85-
<!-- emcc, and mono-aot-cross don't like relative paths for output files -->
86-
<_WasmIntermediateOutputPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'wasm'))</_WasmIntermediateOutputPath>
8785
<_BeforeWasmBuildAppDependsOn />
8886
</PropertyGroup>
8987

@@ -97,6 +95,7 @@
9795
<Target Name="_InitializeCommonProperties">
9896
<Error Condition="'$(MicrosoftNetCoreAppRuntimePackDir)' == '' and ('%(ResolvedRuntimePack.PackageDirectory)' == '' or !Exists(%(ResolvedRuntimePack.PackageDirectory)))"
9997
Text="Could not find %25(ResolvedRuntimePack.PackageDirectory)=%(ResolvedRuntimePack.PackageDirectory)" />
98+
<Error Condition="'$(IntermediateOutputPath)' == ''" Text="%24(IntermediateOutputPath) property needs to be set" />
10099

101100
<PropertyGroup>
102101
<MicrosoftNetCoreAppRuntimePackDir Condition="'$(MicrosoftNetCoreAppRuntimePackDir)' == ''">%(ResolvedRuntimePack.PackageDirectory)</MicrosoftNetCoreAppRuntimePackDir>
@@ -106,11 +105,14 @@
106105

107106
<_WasmRuntimePackIncludeDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'include'))</_WasmRuntimePackIncludeDir>
108107
<_WasmRuntimePackSrcDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'src'))</_WasmRuntimePackSrcDir>
108+
109+
<_WasmIntermediateOutputPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'wasm'))</_WasmIntermediateOutputPath>
109110
</PropertyGroup>
111+
112+
<MakeDir Directories="$(_WasmIntermediateOutputPath)" />
110113
</Target>
111114

112115
<Target Name="_BeforeWasmBuildApp" DependsOnTargets="$(_BeforeWasmBuildAppDependsOn)">
113-
<Error Condition="'$(IntermediateOutputPath)' == ''" Text="%24(IntermediateOutputPath) property needs to be set" />
114116
<Error Condition="!Exists('$(MicrosoftNetCoreAppRuntimePackRidDir)')" Text="MicrosoftNetCoreAppRuntimePackRidDir=$(MicrosoftNetCoreAppRuntimePackRidDir) doesn't exist" />
115117
<Error Condition="@(WasmAssembliesToBundle->Count()) == 0" Text="WasmAssembliesToBundle item is empty. No assemblies to process" />
116118

@@ -122,7 +124,6 @@
122124
<WasmAppDir>$([MSBuild]::NormalizeDirectory($(WasmAppDir)))</WasmAppDir>
123125
</PropertyGroup>
124126

125-
<MakeDir Directories="$(_WasmIntermediateOutputPath)" />
126127
<ItemGroup>
127128
<_WasmAssembliesInternal Include="@(WasmAssembliesToBundle->Distinct())" />
128129

0 commit comments

Comments
 (0)