Created
July 29, 2016 07:54
-
-
Save ashumkin/57b034e232be07452e9c4b865bc2896a to your computer and use it in GitHub Desktop.
FileVersion info set via MSBuild target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' ToolsVersion="12.0"> | |
<PropertyGroup Condition="($(VersionCode)!='' or $(VersionName)!='' or $(FileVersion)!='')"> | |
<_PreResourceBuildTargets>_SetFileVersion</_PreResourceBuildTargets> | |
<CoreBuildDependsOn>$(_PreResourceBuildTargets);$(CoreBuildDependsOn)</CoreBuildDependsOn> | |
</PropertyGroup> | |
<UsingTask TaskName="__SetFileVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll"> | |
<ParameterGroup> | |
<VerInfoKeys ParameterType="System.String" Required="true" /> | |
<VersionCode ParameterType="System.String" Required="false" /> | |
<VersionName ParameterType="System.String" Required="false" /> | |
<FileVersion ParameterType="System.String" Required="false" /> | |
<Out ParameterType="System.String" Output="true" /> | |
</ParameterGroup> | |
<Task> | |
<Code Type="Fragment" Language="cs"><![CDATA[ | |
// split values as CSV (by ";") | |
String[] verInfoKeysList = VerInfoKeys.Split(';'); | |
Dictionary<String, String> d = new Dictionary<String, String>(); | |
foreach (String verInfoValue in verInfoKeysList) { | |
// split values as "key=value" | |
if (! String.IsNullOrEmpty(verInfoValue)) { | |
String[] kv = verInfoValue.Split('='); | |
d.Add(kv[0], kv[1]); | |
} | |
} | |
if (! String.IsNullOrEmpty(VersionCode)) { | |
d.Remove("versionCode"); | |
d.Add("versionCode", VersionCode); | |
} | |
if (! String.IsNullOrEmpty(VersionName)) { | |
d.Remove("versionName"); | |
d.Add("versionName", VersionName); | |
} | |
if (! String.IsNullOrEmpty(FileVersion)) { | |
d.Remove("FileVersion"); | |
d.Add("FileVersion", FileVersion); | |
} | |
List<String> L = new List<String>(); | |
foreach (KeyValuePair<String, String> kv in d) { | |
L.Add(kv.Key + "=" + kv.Value); | |
} | |
_Out = String.Join(";", L.ToArray()); | |
]]></Code> | |
</Task> | |
</UsingTask> | |
<Target Name='_SetVersionCode_Name' > | |
<Message Text="$(VerInfo_Keys)" /> | |
<__SetFileVersion VerInfoKeys="$(VerInfo_Keys)" VersionCode="$(VersionCode)" VersionName="$(VersionName)" FileVersion="$(FileVersion)"> | |
<Output PropertyName="VerInfo_Keys" TaskParameter="Out" /> | |
</__SetFileVersion> | |
<Message Text="$(VerInfo_Keys)" /> | |
</Target> | |
<Target Name='_SetFileVersion'> | |
<CallTarget | |
Targets='_SetVersionCode_Name' | |
/> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a suggestion, but for supporting differing versions of MSBuild