如何读取外部文件的属性值? [英] How to read property value from external file?

查看:143
本文介绍了如何读取外部文件的属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有AssemblyInfo.cs文件生成过程中自动生成的。下面是的.csproj文件的一部分:

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>

但我不知道该怎么.csproj的文件之外指定主要属性,所以我不吨有我想改变的版本,每次卸载的项目。我需要或者从特殊的文本文件中加载它们内部的项目或以某种方式将它们设置在项目属性对话框。有什么建议?

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?

推荐答案

用于 ReadLinesFromFile 来使版本不同的文件:

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)"/>

这篇关于如何读取外部文件的属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆