【问题标题】:Is it possible to set OutputPath in powershell with build macro's?是否可以使用构建宏在 powershell 中设置 OutputPath?
【发布时间】:2015-11-10 13:06:05
【问题描述】:

与本题相关: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>

【问题讨论】:

    标签: 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)"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 2016-07-17
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多