2015-11-10 5 views
2

По этому вопросу: Is it possible to set project's Output Path property from nuget powershell?Можно ли установить OutputPath в powershell со встроенными макросами?

Как установить выходной путь проекта на использование макросов? Также, когда вы редактируете его в файле csproj.

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

Это решает в

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

Но должен был

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

ответ

0

Я нашел обходной путь, изменив csproj с помощью XML

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)"