Search code examples
c#asp.net-web-apimsbuildpowershell-core

Unexpected MSB4184 Error running MSBUILD from Script in PS Core 7.3 -- PS Core Bug or something we can fix?


We've a PS script to orchestrate our builds / deploys that is now failing. I've confirmed this is newly introduced with PS Core 7.3; not occurring on PS Core 7.2.x.

With PS Core 7.3 our script is newly failing with error

C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(321,5): error MSB4184: The expression "[System.IO.Path]::Combine(C:\Source\ourRepo\ourCSProj, bin\"AnyCPU"\DevAzure\)" cannot be evaluated. Illegal characters in path. [C:\Source\ourRepo\ourCSProj\ourCSProj.csproj]

This is a .NET Framework 4.8 project, a WebAPI / Library Project. The command we run is: & "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\MSBuild.exe" ourCSProj\ourCSProj.csproj /p:Platform="AnyCPU" /t:Clean /nologo /p:Configuration=DevAzure /p:VisualStudioVersion=17.0 /v:m /p:SolutionDir=C:\Source\ourRepo\

Running that from the command-line by hand works fine. Our script builds that command and uses this syntax to execute it:

& "$cmd" $cmdArgs $msbuildBaseArgs

$cmd is C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\MSBuild.exe

$msbuildBaseArgs is a non-fixed sized array of items, containing:

/nologo
/p:Configuration=DevAzure
/p:VisualStudioVersion=17.0
/v:m
/p:SolutionDir=C:\Source\oureRepo\

$cmdArgs is also an array, constructed with @( ... ) syntax.

No problems running this script on PS Core 7.2.x and no problem running on Windows Powershell 5.x (Windows 10 box).

What would have changed in PS Core 7.3 that would cause this command (from line 321 of Microsoft.Common.CurrrentVersion.targets to think $OutDir is bin\"AnyCPU"\DevAzure\, which does not exist. Why is it even newly using Platform in that evaluation on PS Core 7.3?

    <TargetDir Condition="'$(OutDir)' != ''">$([MSBuild]::Escape($([System.IO.Path]::GetFullPath(`$([System.IO.Path]::Combine(`$(MSBuildProjectDirectory)`, `$(OutDir)`))`))))</TargetDir>

Solution

  • Have you tried stripping the quotation marks around /p:Platform="AnyCPU"?

    /p:* values have always been passed literally and quotation marks shouldn't be needed there. But it seems ps73/net7 is more strict about these things.

    (I don't think you need the Platform parameter at all, actually.)