Skip to content

Commit 925fa56

Browse files
committed
Adds automatic population of build version to the PS module and help file
1 parent 99d0d4e commit 925fa56

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/Lithnet.ResourceManagement.Automation/Lithnet.ResourceManagement.Automation.csproj

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,34 @@
117117
</None>
118118
<None Include="packages.config" />
119119
</ItemGroup>
120+
<UsingTask TaskName="ReplaceFileText" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
121+
<ParameterGroup>
122+
<InputFilename ParameterType="System.String" Required="true" />
123+
<OutputFilename ParameterType="System.String" Required="true" />
124+
<MatchExpression ParameterType="System.String" Required="true" />
125+
<ReplacementText ParameterType="System.String" Required="true" />
126+
</ParameterGroup>
127+
<Task>
128+
<Reference Include="System.Core" />
129+
<Using Namespace="System" />
130+
<Using Namespace="System.IO" />
131+
<Using Namespace="System.Text.RegularExpressions" />
132+
<Code Type="Fragment" Language="cs">
133+
<![CDATA[
134+
File.WriteAllText(
135+
OutputFilename,
136+
Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
137+
);
138+
]]>
139+
</Code>
140+
</Task>
141+
</UsingTask>
120142
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
121143
<PropertyGroup>
144+
<PostBuildEventDependsOn>
145+
$(PostBuildEventDependsOn);
146+
PostBuildMacros;
147+
</PostBuildEventDependsOn>
122148
<PostBuildEvent>"C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe" sign /sha1 "$(CSCERTTHUMBPRINT)" /t http://timestamp.digicert.com /fd sha256 /v "$(TargetFileName)"
123149

124150
"C:\Program Files\Debugging Tools for Windows (x64)\symstore" add /f "$(TargetDir)*.pdb" /s \\localhost\symbols /t "$(ProjectName)" /v "@(VersionNumber)"
@@ -129,12 +155,24 @@
129155
</PreBuildEvent>
130156
</PropertyGroup>
131157
<Import Project="..\packages\Fody.1.29.2\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.1.29.2\build\dotnet\Fody.targets')" />
158+
<Target Name="PostBuildMacros">
159+
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
160+
<Output TaskParameter="Assemblies" ItemName="Targets" />
161+
</GetAssemblyIdentity>
162+
<ItemGroup>
163+
<VersionNumber Include="@(Targets->'%(Version)')" />
164+
</ItemGroup>
165+
</Target>
132166
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
133167
<PropertyGroup>
134168
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
135169
</PropertyGroup>
136170
<Error Condition="!Exists('..\packages\Fody.1.29.2\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.1.29.2\build\dotnet\Fody.targets'))" />
137171
</Target>
172+
<Target Name="AfterBuild">
173+
<ReplaceFileText InputFilename="$(TargetDir)LithnetRMA.psd1" OutputFilename="$(TargetDir)LithnetRMA.psd1" MatchExpression="\$version\$" ReplacementText="@(VersionNumber)" />
174+
<ReplaceFileText InputFilename="$(ProjectDir)LithnetRMA.Help.pshproj" OutputFilename="$(ProjectDir)LithnetRMA.Help.pshproj" MatchExpression="&lt;Version&gt;.*?&lt;\/Version&gt;" ReplacementText="&lt;Version&gt;@(VersionNumber)&lt;/Version&gt;" />
175+
</Target>
138176
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
139177
Other similar extension points exist, see Microsoft.Common.targets.
140178
<Target Name="BeforeBuild">

src/Lithnet.ResourceManagement.Automation/LithnetRMA.Help.pshproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<ModuleObject xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" fVersion="1.1" type="Manifest" mclass="Module" useSupports="false">
33
<Name>LithnetRMA</Name>
4-
<Version>1.0.6596</Version>
4+
<Version>1.0.6597.17047</Version>
55
<Description>Lithnet Resource Management Client for PowerShell</Description>
66
<HasManifest>true</HasManifest>
77
<OverridePostCount>false</OverridePostCount>

src/Lithnet.ResourceManagement.Automation/LithnetRMA.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@{
1010

1111
# Version number of this module.
12-
ModuleVersion = '1.0.6596'
12+
ModuleVersion = '$version$'
1313

1414
# ID used to uniquely identify this module
1515
GUID = 'd7c36446-aca6-418a-a2a3-cbfc32016a52'

0 commit comments

Comments
 (0)