gpt4 book ai didi

c# - 是否可以使用构建宏在 powershell 中设置 OutputPath?

转载 作者:太空宇宙 更新时间:2023-11-03 15:31:36 24 4
gpt4 key购买 nike

与此问题相关:Is it possible to set project's Output Path property from nuget powershell?

如何设置项目的输出路径以使用宏?就像您在 csproj 文件中编辑它一样。

(Get-Project).ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value =
"$(SolutionDir)bin"

这解决了

<OutputPath>%24%28SolutionDir%29\bin</OutputPath>

但应该是

<OutputPath>$(SolutionDir)\bin</OutputPath>

最佳答案

我通过 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)"

关于c# - 是否可以使用构建宏在 powershell 中设置 OutputPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33630705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com