[wasm] Fix Publish for Blazorwasm projects on VS17 (#56432)
authorAnkit Jain <radical@gmail.com>
Wed, 28 Jul 2021 21:34:02 +0000 (17:34 -0400)
committerGitHub <noreply@github.com>
Wed, 28 Jul 2021 21:34:02 +0000 (17:34 -0400)
commit7b3e22b977724e72363fce9236da7c45a4032905
tree81e3ea0e9137f63020f8a848cae39297034d871d
parent39803d4d3cbf818641437afb7402da15fa076bec
[wasm] Fix Publish for Blazorwasm projects on VS17 (#56432)

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 d574b032793ae752387d32b97ff9840de17420a2
Author: Ankit Jain <radical@gmail.com>
Date:   Mon Jul 19 01:02:01 2021 -0400

    [wasm] Add support for using custom native libraries (#55797)
```
src/mono/wasm/build/WasmApp.Native.targets
src/mono/wasm/build/WasmApp.targets