[英]Visual Studio Android solution stops building upon hitting C# version conflict when using MSBuild
[英]Customizations on MSBuild (like version) for a C# solution
我認為最終結果將是“不可能那么容易地完成”,但似乎應該如此。 我有一個正在進行的個人項目。 我討厭不得不手動(甚至在腳本中)更改版本,公司,版權以及所有assembly.cs文件上的所有內容,並且希望所有這些內容都可以在腳本或我可以更改的文件中進行(因此該腳本在大多數情況下都保持不變)。 但是,似乎MSBuild主要是“ Visual Studio中指定的內部版本”。 我只是不想擁有這些文件的所有歷史記錄,而只更改版本,甚至可能會犯一個錯誤,因為該項目將繼續變得越來越大。 我只想能夠向Visual Studio中添加一個新項目,並在我的Powershell腳本中添加任何命令行即可,只需說“編譯此文件,但是給它這個公司名稱和這個文件版本,而不是代碼文件中列出的內容即可。 ”。
Google尚未在此方面取得成果。 我什至發現很難將文件構建到特定文件夾中。 到目前為止,我必須確保我的所有項目都位於2個文件夾中,並且能夠說要在.... \\上進行構建,但是如果我願意,可以將其隨機更改,並在其他位置進行構建如果我願意的話。
MSBuild也許不是走的路? 是否還有其他方法可以從命令行構建Visual Studio? 最終,我還希望使用wix自動構建安裝程序,並使其版本與二進制版本匹配。
謝謝
由於csproj是xml,因此在進行構建之前,可以使用XmlUpdate“ helpers”修改csproj文件中的值。
對於其他文件,您可以使用其他一些任務來完成工作。
這是一個有用的目標:
http://msbuildtasks.tigris.org/和/或https://github.com/loresoft/msbuildtasks具有(FileUpdate(如果是Source-Control,則為SvnVersion任務))任務。
<Target Name="BeforeBuild_VersionTagIt_Target">
<ItemGroup>
<AssemblyInfoFiles Include="$(ProjectDir)\**\*AssemblyInfo.cs" />
</ItemGroup>
<!--
<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(SVNToolPath)">
<Output TaskParameter="Revision" PropertyName="MyRevision" />
</SvnVersion>
-->
<PropertyGroup>
<MyRevision>9999</MyRevision>
</PropertyGroup>
<FileUpdate Files="@(AssemblyInfoFiles)"
Regex="AssemblyFileVersion\("(\d+)\.(\d+)\.(\d+)\.(\d+)"
ReplacementText="AssemblyFileVersion("$1.$2.$3.$(MyRevision)" />
</Target>
下面是操縱csproj(xml)的示例。
如何使用MSBuild將鏈接文件添加到csproj文件。 (3.5框架)
但基本上,在構建時,可以將所有重復性內容放入msbuild定義文件中(通常使用擴展名.proj或.msbuild)...並調用msbuild.exe MyFile.proj。
在.proj文件中,您將引用.sln文件。
例如:
$(WorkingCheckout)將是一個變量(在此未定義)...具有從源代碼管理那里獲取hte代碼副本的目錄。
<Target Name="BuildIt" >
<MSBuild Projects="$(WorkingCheckout)\MySolution.sln" Targets="Build" Properties="Configuration=$(Configuration)">
<Output TaskParameter="TargetOutputs" ItemName="TargetOutputsItemName"></Output>
</MSBuild>
<Message Text="BuildItUp completed" />
</Target>
因此,下面是更完整的示例。 您可以將其保存為“ MyBuild.proj”,然后調用
"msbuild.exe" "MyBuild.proj".
啟動.proj代碼。 (注意,我沒有導入FileUpdate Task的庫)
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
<PropertyGroup>
<!-- Always declare some kind of "base directory" and then work off of that in the majority of cases -->
<WorkingCheckout>.</WorkingCheckout>
</PropertyGroup>
<Target Name="AllTargetsWrapped">
<CallTarget Targets="BeforeBuild_VersionTagIt_Target" />
<CallTarget Targets="BuildItUp" />
</Target>
<Target Name="BuildItUp" >
<MSBuild Projects="$(WorkingCheckout)\MySolution.sln" Targets="Build" Properties="Configuration=$(Configuration)">
<Output TaskParameter="TargetOutputs" ItemName="TargetOutputsItemName"></Output>
</MSBuild>
<Message Text="BuildItUp completed" />
</Target>
<Target Name="BeforeBuild_VersionTagIt_Target">
<ItemGroup>
<AssemblyInfoFiles Include="$(ProjectDir)\**\*AssemblyInfo.cs" />
</ItemGroup>
<!--
<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(SVNToolPath)">
<Output TaskParameter="Revision" PropertyName="MyRevision" />
</SvnVersion>
-->
<PropertyGroup>
<MyRevision>9999</MyRevision>
</PropertyGroup>
<FileUpdate Files="@(AssemblyInfoFiles)"
Regex="AssemblyFileVersion\("(\d+)\.(\d+)\.(\d+)\.(\d+)"
ReplacementText="AssemblyFileVersion("$1.$2.$3.$(MyRevision)" />
</Target>
</Project>
為了增強上述功能,您將創建一個在“ BeforeBuild_VersionTagIt_Target”之前運行的新目標,該目標將從源代碼管理中提取您的代碼並將其放在$(WorkingCheckout)文件夾中。
基本步驟如下:1.從Source-Control檢出代碼。 2.運行更改AssemblyVersion的目標(以及您要操縱的其他目標),然后3.生成.sln文件。
這就是.proj文件的基礎。 您可以做更多的事情。 通常通過使用已經存在的幫助程序庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.