How to read property value from external file?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 18:28:15

Used ReadLinesFromFile to make version in separate file:

<ReadLinesFromFile File="Properties\Version.txt">
    <Output TaskParameter="Lines" ItemName="Ver" />
</ReadLinesFromFile>
<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="C:\Program Files (x86)\VisualSVN Server\bin">
    <Output TaskParameter="Revision" PropertyName="Revision" />
</SvnVersion>
<Message Text="Version: @(Ver).$(Revision)" />
<AssemblyInfo 
    CodeLanguage="CS" 
    OutputFile="$(MSBuildProjectDirectory)\Properties\VersionInfo.cs" 
    AssemblyVersion="@(Ver).$(Revision)" 
    AssemblyFileVersion="@(Ver).$(Revision)"/>

Use property pages, so you could set these properties on the project property sheets dialogs.

You will need to create a properties file and edit your project file (only once) to add an import directive to your properties file. Here is an example.

You can use your external tools

<Exec Command="newversion incMinor AssemblyInfo.cs > newversion.log" /> 
KazR

If it's locking of the csproj files by VS that's your concern, my answer to this question - How to turn off caching of build definitions in Visual studio might help you.

You could move the content of your BeforeBuild task (including the version propertygroup) into a separate proj file and invoke it with an MSBuild task (using a random filename generated by the example in the linked answer above). This would allow you to manually edit your version number properties without having to unload/load your csproj file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!