【问题标题】:Update project property with a powershell script使用 powershell 脚本更新项目属性
【发布时间】:2015-04-15 01:43:10
【问题描述】:

我想创建一个 nuget 包,它将在 C# 项目中恢复时运行 Powershell 脚本。该脚本将更改项目中项目属性的值,例如:

设定值

<AssemblyVersion>1.0.0.0</AssemblyVersion>

<AssemblyVersion>$(ReleaseApplicationVersion)</AssemblyVersion>

以及其他一些属性。

提前致谢!

更新-------------------------------

这就是我所拥有的

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

$proj = Resolve-Path $projectName

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

但我显然不知道如何完成这项工作,因为我遇到了一堆问题。谢谢

【问题讨论】:

标签: powershell msbuild nuget csproj


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-18
    • 2015-02-19
    • 2017-10-01
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多