【问题标题】:Is it possible to set OutputPath in powershell with build macro's?是否可以使用构建宏在 powershell 中设置 OutputPath?
【发布时间】:2015-11-10 13:06:05
【问题描述】:
【问题讨论】:
标签:
c#
powershell
nuget
csproj
【解决方案1】:
我通过 xml 更改 csproj 找到了解决方法
function Set-OutputPathRaw( $projectObj, $outputPath )
{
<#
.SYNOPSIS
Set the output path directly in the csproj file
.PARAMETER projectObj
The project to set
.PARAMETER outputPath
The path to set in the output path. May use dollar-sign macros
#>
$projectObj.Save() # save beforehand
$csproj = [xml](Get-Content $projectObj.FullName)
$nsmgr = New-Object System.Xml.XmlNamespaceManager -ArgumentList $csproj.NameTable
$nsmgr.AddNamespace('a', 'http://schemas.microsoft.com/developer/msbuild/2003')
$outputpathnodes = $csproj.SelectNodes('/a:Project/a:PropertyGroup/a:OutputPath/text()',$nsmgr)
foreach($outputnode in $outputpathnodes)
{
$outputnode.Value = $outputPath
}
$csproj.Save($projectObj.FullName)
}
通过以下方式调用:
Set-OutputPathRaw $project "`$(SolutionRoot)\bin\`$(Configuration)"