2

Related to this question: Is it possible to set project's Output Path property from nuget powershell?

How can I set the output path of a project to use macro's? Just as when you edit it in the csproj file.

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

This resolves in

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

But should have been

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

1 Answer 1

0

I found a workaround by changing the csproj via 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)
}

Call this via:

Set-OutputPathRaw $project "`$(SolutionRoot)\bin\`$(Configuration)"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.