ApplicationInsights-JS/Package.targets

89 строки
4.9 KiB
XML

<?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 "$(OutDir)\"</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>
<Target Name="PrepareNuGetForSigning" BeforeTargets="SignFiles" DependsOnTargets="BuildNugetPackage">
<ItemGroup>
<FilesToSign Include="$(OutDir)\**\*.nupkg">
<Authenticode>NuGet</Authenticode>
</FilesToSign>
</ItemGroup>
</Target>
<Target Name="MoveNuGetFilesAfterSigning" AfterTargets="SignFiles">
<ItemGroup>
<FilesToMove Include="$(OutDir)*.nupkg" />
</ItemGroup>
<!-- Move the NuGet files from the OutDir to PackageOutputDir -->
<Move SourceFiles="@(FilesToMove)" DestinationFolder="$(PackageOutputDir)" />
</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>