forked from microsoft/ApplicationInsights-dotnet-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.targets
75 lines (66 loc) · 4.56 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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.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>
<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 "coresdkversion=$(CoreSdkVersion);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 -->
<Error Condition="'$(CoreSdkVersion)' == ''" Text="CoreSdkVersion property must be a valid version of Core SDK included in Global.props."/>
<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 "Src\Microsoft.ApplicationInsights.Web.sln" -u https://github.com/Microsoft/ApplicationInsights-server-dotnet -c "$(Configuration)" -p "$(Platform)"' IgnoreExitCode='true' />
</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>