forked from microsoft/ApplicationInsights-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.targets
73 lines (64 loc) · 4.36 KB
/
Package.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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This target runs after all referenced projects have been built, but before the *.FileListAbsolute.txt file gets saved to support incremental build. -->
<Target Name="PrepareForNugetPackaging" AfterTargets="ResolveProjectReferences">
<Error Condition="!Exists('$(PackageSpecFile)')" Text="PackageSpecFile must be a valid path to a .nuspec file that defines NuGet package structure."/>
<!-- Read PackageId from the .nuspec file -->
<XmlPeek XmlInputPath="$(PackageSpecFile)" Query="/package/metadata/id/text()">
<Output TaskParameter="Result" PropertyName="PackageId"/>
</XmlPeek>
<!-- Mark .nupkg file as generated by build so that Clean can remove it -->
<ItemGroup>
<FileWrites Include="$(PackageOutputDir)\$(PackageId)*.nupkg" />
<FileWrites Include="$(PackageOutputDir)\$(PackageId)*.symbols.nupkg" Condition="'$(PackageSymbols)' == 'True'"/>
</ItemGroup>
</Target>
<!-- This target runs after build to guarantee that all dependent files have already been copied to output directory. -->
<Target Name="BuildNugetPackage" AfterTargets="Build">
<Error Condition="!Exists('$(PackageVersionFile)')" Text="PackageVersionFile must be a valid path to a .dll file that defines NuGet package version information."/>
<!-- Extract package properties from the .dll file -->
<GetFileVersionInfo File="$(PackageVersionFile)">
<Output TaskParameter="VersionInfo" ItemName="VersionInfo" />
</GetFileVersionInfo>
<PropertyGroup>
<PackageVersion>@(VersionInfo->'%(FileMajorPart)').@(VersionInfo->'%(FileMinorPart)').@(VersionInfo->'%(FileBuildPart)')</PackageVersion>
<PackageVersion Condition="'$(StableRelease)' != 'True'">$(PackageVersion)-build@(VersionInfo->'%(FilePrivatePart)')</PackageVersion>
<PackageAuthor>@(VersionInfo->'%(CompanyName)')</PackageAuthor>
<PackageImage>http://appanacdn.blob.core.windows.net/cdn/icons/aic.png</PackageImage>
<PackageCopyright>@(VersionInfo->'%(LegalCopyright)')</PackageCopyright>
<PackageSymbols Condition="'$(PackageSymbols)' == ''">false</PackageSymbols>
<PackageCommand>$(NuGetCommand) pack "$(PackageSpecFile)" -Properties "version=$(PackageVersion);author=$(PackageAuthor);image=$(PackageImage);copyright=$(PackageCopyright);configuration=$(Configuration)" -BasePath "$(BinRoot)" -OutputDirectory "$(PackageOutputDir)"</PackageCommand>
<PackageCommand Condition="'$(PackageSymbols)' == 'True'">$(PackageCommand) -Symbols</PackageCommand>
</PropertyGroup>
<RemoveDir Directories="$(PackageOutputDir)"/>
<!-- Make sure package output directory exists (expected by NuGet). -->
<MakeDir Directories="$(PackageOutputDir)"/>
<!-- Generate .nupkg file -->
<Exec Command="$(PackageCommand)" />
</Target>
<UsingTask TaskName="GetFileVersionInfo" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<File ParameterType="System.String" Required="true" />
<VersionInfo ParameterType="Microsoft.Build.Framework.ITaskItem" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.Diagnostics" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(this.File);
this.VersionInfo = new TaskItem(this.File);
this.VersionInfo.SetMetadata("Comments", versionInfo.Comments);
this.VersionInfo.SetMetadata("CompanyName", versionInfo.CompanyName);
this.VersionInfo.SetMetadata("FileMajorPart", versionInfo.FileMajorPart.ToString());
this.VersionInfo.SetMetadata("FileMinorPart", versionInfo.FileMinorPart.ToString());
this.VersionInfo.SetMetadata("FileBuildPart", versionInfo.FileBuildPart.ToString());
this.VersionInfo.SetMetadata("FilePrivatePart", versionInfo.FilePrivatePart.ToString().PadLeft(5,'0'));
this.VersionInfo.SetMetadata("LegalCopyright", versionInfo.LegalCopyright);
this.VersionInfo.SetMetadata("ProductName", versionInfo.ProductName);
]]>
</Code>
</Task>
</UsingTask>
</Project>