Skip to content

Instantly share code, notes, and snippets.

@SelvinPL
Created November 9, 2018 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SelvinPL/bc26f84b6096335e3c9bcad1c258b967 to your computer and use it in GitHub Desktop.
Save SelvinPL/bc26f84b6096335e3c9bcad1c258b967 to your computer and use it in GitHub Desktop.
BuildConstant.targets
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="SetupBuildInfoProperty" BeforeTargets="CoreCompile">
<ItemGroup>
<BuildInfoProperty Include="Configuration"/>
<BuildInfoProperty Include="ProjectDir"/>
</ItemGroup>
</Target>
<Target Name="GenereteBuildInfo" BeforeTargets="CoreCompile" >
<PropertyGroup>
<BuildInfoFile>$(IntermediateOutputPath)BuildInfo.$(Configuration).cs</BuildInfoFile>
</PropertyGroup>
<ItemGroup>
<BuildInfoPropertyExpanded Include="@(BuildInfoProperty)">
<Value>$(%(BuildInfoProperty.Identity).Replace('"','""'))</Value>
</BuildInfoPropertyExpanded>
</ItemGroup>
<PropertyGroup>
<BuildInfoFileLines>public static class BuildInfo;{;@(BuildInfoPropertyExpanded->'public const string %(Identity)=@&quot;%(Value)&quot;%3b');}</BuildInfoFileLines>
</PropertyGroup>
<WriteLinesToFile
File="$(BuildInfoFile)"
Lines="$(BuildInfoFileLines)"
Overwrite="true"
Encoding="Unicode" Condition="'$(BuildInfoFileLines)' != ''">
</WriteLinesToFile>
<ItemGroup>
<Compile Include="$(BuildInfoFile)" />
</ItemGroup>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment