PowerShell 7.3 breaks invoking exe with params

103 views Asked by At

After an upgrade from PowerShell v. 7.2.7 to v. 7.3, invoking executables with parameters started to fail consistently with various errors.

It looks like the parameters are not passed in correctly anymore.

An example (some params removed for brevity):

 msbuild.exe "$Solution" /maxcpucount:1 `
                /t:Build `
                /p:Configuration=$Configuration `   
                "/l:TeamCity.MSBuild.Logger.TeamCityMSBuildLogger,$RootDir\.build\packages\TeamCity.Dotnet.Integration\build\_common\msbuild15\TeamCity.MSBuild.Logger.dll;teamcity"

fails with:

MSBUILD : error MSB1021: Cannot create an instance of the logger. Could not load file or assembly ''JetBrains.BuildServer.MSBuildLoggers.MSBuildLogger\,"D:\\BuildAgentA\\plugins\\dotnetPlugin\\bin\\JetBrains.BuildServer.MSBuildLoggers.4.0.dll"'' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
1

There are 1 answers

0
Grzegorz Smulko On

The solution is to use splatting:

$params = @(
    "$Solution",
    "/maxcpucount",
    "/t:Build",
    "/p:Configuration=$Configuration"
)

if ($env:TEAMCITY_VERSION) {
    $params += "/l:TeamCity.MSBuild.Logger.TeamCityMSBuildLogger,$RootDir\.build\packages\TeamCity.Dotnet.Integration\build\_common\msbuild15\TeamCity.MSBuild.Logger.dll;teamcity"
}

msbuild @params

Note that it's msbuild @params, not msbuild $params.