forked from microsoft/ApplicationInsights-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Package.targets
79 lines (69 loc) · 5.01 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
74
75
76
77
78
79
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project=".\NuGet.Targets" />
<!-- 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="'$(PreReleaseMilestone)' != ''">$(PackageVersion)-$(PreReleaseMilestone)</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>
<PackageCommand>$(NuGetCommand) pack "$(PackageSpecFile)" -Properties "version=$(PackageVersion);author=$(PackageAuthor);image=$(PackageImage);copyright=$(PackageCopyright);configuration=$(Configuration)" -BasePath "$(BinRoot)" -OutputDirectory "$(PackageOutputDir)" -Symbols</PackageCommand>
</PropertyGroup>
<!-- Make sure package output directory exists (expected by NuGet). -->
<MakeDir Directories="$(PackageOutputDir)"/>
<!-- Generate .nupkg file -->
<Exec Command="$(PackageCommand)" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
</Target>
<Target Name="Gitlink" AfterTargets="Build" BeforeTargets="BuildNugetPackage">
<Exec Command='$(PackagesDir)\gitlink.2.2.0\lib\net45\GitLink.exe $(MSBuildThisFileDirectory) -f "Microsoft.ApplicationInsights.sln" -u https://github.com/Microsoft/ApplicationInsights-dotnet -c "$(Configuration)" -p "$(Platform)"' IgnoreExitCode='true' />
<Exec Command='$(PackagesDir)\gitlink.2.2.0\lib\net45\GitLink.exe $(MSBuildThisFileDirectory) -f "Microsoft.ApplicationInsights.Channels.sln" -u https://github.com/Microsoft/ApplicationInsights-dotnet -c "$(Configuration)" -p "$(Platform)"' IgnoreExitCode='true' />
</Target>
<UsingTask TaskName="GetFileVersionInfo" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildFrameworkToolsPath)\Microsoft.Build.Tasks.v4.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>