3

I want to create a nuget package which will run a Powershell script on restore in a C# project. The script will change the values of the project properties on the project e.g.:

Set value of

<AssemblyVersion>1.0.0.0</AssemblyVersion>

to

<AssemblyVersion>$(ReleaseApplicationVersion)</AssemblyVersion>

and some other properties.

Thanks in advance!

UPDATE-------------------------------------------

This is what I have

param([string]$projectName = $(throw 'csproj file is required'))

$proj = Resolve-Path $projectName

$propAssemblyName = $proj.Properties.Item("AssemblyName")
$propAssemblyName.Value = '$(ReleasedAssemblyName)'

But I obviously dont know how to make this work as I get bunch of issues. Thanks

2

1 Answer 1

2
function Set-Version {
    Write-Header "Updating version in .csproj files"
 
    try {
        Push-Location ".\csprojLocation"
        $versionProjFile = Resolve-Path "*.csproj"
        $xml = [xml](Get-Content $versionProjFile)
        $xml.Project.PropertyGroup.AssemblyVersion = ${version}
        $xml.Save($versionPropsFile)
    }
    finally {
        Pop-Location
    }
}
 
Set-Version
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.