Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read property value from external file?

I have AssemblyInfo.cs file automatically generated during build. Here's part of .csproj file:

<PropertyGroup>
    <Major>2</Major>
    <Minor>3</Minor>
    <Build>0</Build>
    <Revision>0</Revision>
</PropertyGroup>
<Target Name="BeforeBuild">
    <SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="C:\Program Files\VisualSVN Server\bin">
        <Output TaskParameter="Revision" PropertyName="Revision" />
    </SvnVersion>
    <AssemblyInfo CodeLanguage="CS" 
                  OutputFile="$(MSBuildProjectDirectory)\Properties\VersionInfo.cs" 
                  AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)" 
                  AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"/>
</Target>

But I don't know how to specify Major and Minor properties outside .csproj file so I don't have to unload project every time I want to change version. I need either to load them from special text file inside project or to somehow set them in project properties dialog. Any suggestions?

like image 349
Poma Avatar asked Apr 21 '11 15:04

Poma


1 Answers

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)"/>
like image 152
Poma Avatar answered Oct 31 '22 04:10

Poma