如何从外部文件读取属性值?

| 我有在生成过程中自动生成的AssemblyInfo.cs文件。这是.csproj文件的一部分:
<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文件之外指定
Major
Minor
属性,因此我不必每次想更改版本时都卸载项目。我需要从项目内部的特殊文本文件中加载它们,或者以某种方式在项目属性对话框中对其进行设置。有什么建议么?     
已邀请:
使用
ReadLinesFromFile
在单独的文件中制作版本:
<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)\"/>
    
使用属性页,因此您可以在项目属性表对话框中设置这些属性。 您将需要创建一个属性文件并编辑您的项目文件(仅一次),以将导入指令添加到您的属性文件中。这是一个例子。     
您可以使用外部工具
<Exec Command=\"newversion incMinor AssemblyInfo.cs > newversion.log\" /> 
    
如果您关心的是VS锁定csproj文件,那么我对这个问题的解答-如何在Visual Studio中关闭生成定义的缓存可能会有所帮助。 您可以将BeforeBuild任务的内容(包括版本属性组)移动到一个单独的proj文件中,并使用MSBuild任务(使用上面链接的答案中的示例生成的随机文件名)调用它。这样一来,您就可以手动编辑版本号属性,而不必卸载/加载csproj文件。     

要回复问题请先登录注册