Exclusion of running powershell script from MSBuild Exec task

I have a problem with MSBuild and Powershell. There is a PS script that I want to execute in MSBuild exec-Task.

Problem: Running Script directly from CMD works, but running Script in MSBuild, I get an error.

Here's the MSBuild script:

<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

<PropertyGroup>  
    <PathToSvnClient>C:\Program Files (x86)\CollabNet\Subversion Client</PathToSvnClient>
</PropertyGroup>

<ItemGroup>
    <!-- set Folder to Svn Repository for svn info command-->
    <SvnFolder Include="$(MSBuildProjectDirectory)\.."/>
</ItemGroup>

<Target Name="SvnInfo">
    <!-- get SVN Revision and Repository Path -->
    <SvnInfo LocalPath="%(SvnFolder.FullPath)" ToolPath="$(PathToSvnClient)">
        <Output TaskParameter="Revision" PropertyName="Revision" />
        <Output TaskParameter="RepositoryPath" PropertyName="RepositoryPath" />
    </SvnInfo>
</Target>

<Target Name="SetProductVersion" DependsOnTargets="SvnInfo">
    <Exec Command="powershell -file &quot;Scripts\SetSth.ps1&quot; -PARAM &quot;$(PathToSth)&quot; -SVNID $(Revision) -SVNFOLDER &quot;$(RepositoryPath)&quot;" LogStandardErrorAsError="true" ContinueOnError="false"/>
</Target>

The command runs exactly the same as in CMD, but I get an exception from Powershell Script for the SVNFOLDER parameter.

The executed command looks like this:

powershell -file "Scripts\SetSth.ps1" -PARAM "C:\abc\cde" -SVNID 1234
-SVNFOLDER "https://domain/svn/rep/branches/xy%20(Build%2012)" 

So, from CMD it works, from inside MSBuild not. I have no idea why. Hope you have an idea.

+3
source share
2 answers

How about this approach playing with double and single quotes:

<Target Name="SetProductVersion" DependsOnTargets="SvnInfo">
    <Exec Command="powershell -command &quot;&amp; {Scripts\SetSth.ps1 -PARAM '$(PathToSth)' -SVNID '$(Revision)' -SVNFOLDER '$(RepositoryPath)'}&quot;" LogStandardErrorAsError="true" ContinueOnError="false"/>
</Target>
+3
source

Double check your paths.

, powershell, , Msbuild.exe , . msbuild.exe cmd.exe , msbuild.

-file "Scripts\SetSth.ps1" C:\users\yourusername\Scripts\SetSth.ps1

, , cmd.exe , , b/c C:\users\yourusername

msbuild.exe, , , - * C:\Windows\Microsoft.NET\Framework\v4.0 *

, C:\Windows\Microsoft.NET\Framework\v4.0\Scripts\SetSth.ps1

. , cmd.exe msbuild. .

+1

Source: https://habr.com/ru/post/1790282/


All Articles