[ACCEPTED]-How to read property value from external file?-csproj
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)"/>
0
It is possible to do this using the ability 7 of PropertyFunctions to call certain .NET functions directly. Essentially, you 6 can call File.ReadAllText() when setting a property value.
<PropertyGroup>
<Version>$([System.IO.File]::ReadAllText("Version.txt"))</Version>
</PropertyGroup>
<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="C:\Program Files (x86)\VisualSVN Server\bin">
<Output TaskParameter="Revision" PropertyName="Revision" />
</SvnVersion>
<Message Text="Version: $(Version).$(Revision)" />
<AssemblyInfo
CodeLanguage="CS"
OutputFile="$(MSBuildProjectDirectory)\Properties\VersionInfo.cs"
AssemblyVersion="$(Version).$(Revision)"
AssemblyFileVersion="$(Version).$(Revision)"/>
The 5 Version.txt file would just contain the 4 first three version numbers, i.e. "1.2.3" or 3 whatever.
I'm not sure exactly when this 2 was added to MSBuild, but it was probably 1 after this question was asked and answered.
Use property pages, so you could set these properties 4 on the project property sheets dialogs.
You 3 will need to create a properties file and 2 edit your project file (only once) to add 1 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" />
0
If it's locking of the csproj files by VS 10 that's your concern, my answer to this question 9 - How to turn off caching of build definitions in Visual studio might help you.
You could move the content 8 of your BeforeBuild task (including the 7 version propertygroup) into a separate proj 6 file and invoke it with an MSBuild task 5 (using a random filename generated by the 4 example in the linked answer above). This 3 would allow you to manually edit your version 2 number properties without having to unload/load 1 your csproj file.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.