-
Notifications
You must be signed in to change notification settings - Fork 7
/
DD4T DI.Targets
149 lines (124 loc) · 6.52 KB
/
DD4T DI.Targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<ProductName>$(MSBuildProjectName)</ProductName>
<!-- Source Directories -->
<BaseDirectory Condition="'$(BaseDirectory)' == ''">$(MSBuildProjectDirectory)</BaseDirectory>
<BaseDirectory Condition="!Exists('$(BaseDirectory)\source')">..\..</BaseDirectory>
<SourceDirectory>$(BaseDirectory)\source</SourceDirectory>
<!-- Build Directories -->
<BuildOutputDirectory>$(BaseDirectory)\build</BuildOutputDirectory>
<BuildBinDirectory>$(BuildOutputDirectory)\bin</BuildBinDirectory>
<BuildDocDirectory>$(BuildOutputDirectory)\doc</BuildDocDirectory>
<BuildLogDirectory>$(BuildOutputDirectory)\log</BuildLogDirectory>
<BuildPackageDirectory>$(BuildOutputDirectory)\package</BuildPackageDirectory>
<BuildWorkDirectory>$(BuildOutputDirectory)\work</BuildWorkDirectory>
<BuildNuGetDirectory>$(BuildPackageDirectory)\lib</BuildNuGetDirectory>
<BuildNuGetFramework40Directory>$(BuildNuGetDirectory)\net40</BuildNuGetFramework40Directory>
<BuildNuGetFramework45Directory>$(BuildNuGetDirectory)\net45</BuildNuGetFramework45Directory>
<NuGetFolder>$(SourceDirectory)\.nuget</NuGetFolder>
<ConfigurationDirectory>$(BaseDirectory)\configuration</ConfigurationDirectory>
<!-- NuSpec file for NuGet Package creation -->
<NuSpecFileName>DD4T.DI.nuspec</NuSpecFileName>
<NuSpecFile>$(ConfigurationDirectory)\$(NuSpecFileName)</NuSpecFile>
</PropertyGroup>
<ItemGroup>
<CleanFolders Include="$(BuildOutputDirectory)"/>
<CleanFolders Include="TestResults"/>
<NuGetStructureFolders Include="$(BuildNugetDirectory);$(BuildNuGetFramework40Directory);$(BuildNuGetFramework45Directory)"/>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<!-- Task for retrieving ProductVersion from an Assembly -->
<UsingTask TaskName="GetInformationalVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<AssemblyFile ParameterType="System.String" Required="true" />
<Version ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("Getting version details of assembly " + this.AssemblyFile, MessageImportance.High);
this.Version = FileVersionInfo.GetVersionInfo(this.AssemblyFile.Split(';')[0]).ProductVersion;
Log.LogMessage("AssemblyVersion: " + this.Version, MessageImportance.High);
]]>
</Code>
</Task>
</UsingTask>
<!-- Task for generating a new version for local development -->
<UsingTask TaskName="GetNewDevVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<OldVersion ParameterType="System.String" Required="true" />
<NewVersion ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("Getting a new version for " + this.OldVersion, MessageImportance.High);
Version version = new Version(this.OldVersion.Split('-')[0]);
this.NewVersion = version.ToString() + "-build" + DateTime.Now.ToString("yyyyMMddHHmmss");
Log.LogMessage("New Version: " + this.NewVersion, MessageImportance.High);
]]>
</Code>
</Task>
</UsingTask>
<Target Name="CleanUp">
<!-- Clean removes all build artifacts to prepare for a new build. -->
<RemoveDir Directories="@(CleanFolders)" />
<MSBuild Projects="$(SolutionFile)" Targets="Clean" />
</Target>
<Target Name="Package">
<ItemGroup>
<PackageFilesCleanup Include="$(BuildPackageDirectory)\**\*.*"/>
</ItemGroup>
<Delete Files="@(PackageFilesCleanup)" />
<MakeDir Directories="@(NuGetStructureFolders)"/>
<ItemGroup>
<MainPackageFiles Include="$(BuildBinDirectory)\**\*.dll;$(BuildBinDirectory)\**\*.pdb;$(BuildBinDirectory)\**\*.xml" Exclude="$(BuildBinDirectory)\**\*CodeAnalysis*.xml"/>
</ItemGroup>
<!-- Get the productversion from the assemblies -->
<GetInformationalVersion AssemblyFile="@(MainPackageFiles)">
<Output TaskParameter="Version" PropertyName="VersionInfo"/>
</GetInformationalVersion>
<!-- Get the productversion from the assemblies -->
<GetNewDevVersion OldVersion="$(VersionInfo)" Condition="'$(Configuration)' == 'Debug'">
<Output TaskParameter="NewVersion" PropertyName="VersionInfo"/>
</GetNewDevVersion>
<Message Text="Got a new version: $(VersionInfo)" Importance="High"/>
<ItemGroup>
<NuGetFiles Include="$(NuSpecFile)"/>
</ItemGroup>
<Copy SourceFiles="@(NuGetFiles)" DestinationFiles="@(NuGetFiles->'$(BuildPackageDirectory)\%(Filename)%(Extension)')"/>
<Copy SourceFiles="@(MainPackageFiles)" DestinationFiles="@(MainPackageFiles->'$(BuildBinDirectory)\%(Filename)%(Extension)')"/>
<PropertyGroup>
<NuSpecFile>$(BuildPackageDirectory)\$(NuSpecFileName)</NuSpecFile>
</PropertyGroup>
<!-- Update version in nuspec file -->
<XmlUpdate XmlFileName="$(NuSpecFile)" XPath="//version" Value="$(VersionInfo)" />
<Copy SourceFiles="@(MainPackageFiles)" DestinationFiles="@(MainPackageFiles->'$(BuildNuGetFramework40Directory)\%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(MainPackageFiles)" DestinationFiles="@(MainPackageFiles->'$(BuildNuGetFramework45Directory)\%(RecursiveDir)%(Filename)%(Extension)')" />
<!-- Create NuGet package -->
<Exec Command='$(NuGetFolder)\nuget.exe pack "$(NuSpecFile)"' WorkingDirectory="$(BuildPackageDirectory)"/>
<Delete Files="$(NuSpecFile)" />
<!-- Create ZipPackage -->
<Zip Files="@(MainPackageFiles)" ZipFileName="$(BuildPackageDirectory)\$(ProductName).$(VersionInfo).zip" WorkingDirectory="$(BuildBinDirectory)" />
<RemoveDir Directories="$(BuildWorkDirectory)" />
</Target>
<Target Name="BeforeBuild">
<ItemGroup>
<ReferenceNew Include="@(Reference)">
<Private>False</Private>
</ReferenceNew>
<Reference Remove="@(Reference)"/>
<Reference Include="@(ReferenceNew)"/>
</ItemGroup>
</Target>
<Target Name="Install">
<ItemGroup>
<NuGetPackage Include="$(BuildPackageDirectory)\**\*.nupkg"/>
</ItemGroup>
<Copy SourceFiles="@(NuGetPackage)" DestinationFolder="$(NUGET_LOCALREPO)" />
</Target>
</Project>