summaryrefslogtreecommitdiff
path: root/Tools/PackageLibs.targets
blob: 9e9e46d0cc510497e6f466d0fefcb9ab771e507b (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Condition="'$(_PackagingCommonTargetsImported)' != 'true'" Project="Packaging.common.targets"/>

  <Target Name="UpdatePkgProjProjectReferences" BeforeTargets="AssignProjectConfiguration">
    <!-- Update PkgProj references to call the GetPackageAssets target -->
    <ItemGroup>
      <ProjectReference Condition="'%(ProjectReference.Extension)'=='.pkgproj'">
        <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
        <Targets>GetPackageAssets</Targets>
        <OutputItemType>PkgProjAsset</OutputItemType>
        <UndefineProperties>%(ProjectReference.UndefineProperties);OSGroup;TargetGroup</UndefineProperties>
      </ProjectReference>
    </ItemGroup>
  </Target>

  <PropertyGroup>
    <!-- Resolve from pkgProjs before nuget packages -->
    <ResolveNugetPackagesDependsOn>$(ResolveNugetPackagesDependsOn);ResolvePkgProjReferences</ResolveNugetPackagesDependsOn>
    <ResolvePkgProjReferencesDependsOn>$(ResolvePkgProjReferencesDependsOn);ResolveProjectReferences</ResolvePkgProjReferencesDependsOn>
  </PropertyGroup>

  <!-- Resolves applicable files from all files in PkgProjs. Similar to ResolveNuGetPackageAssets, except operates on a file list
       without requiring actual nupkgs, project.json, or restore -->
  <Target Name="ResolvePkgProjReferences" Condition="'@(PkgProjAsset)' != ''" DependsOnTargets="$(ResolvePkgProjReferencesDependsOn)">
    <GetApplicableAssetsFromPackages PackageAssets="@(PkgProjAsset)"
                                     TargetMonikers="$(NuGetTargetMoniker)"
                                     RuntimeTargetMonikers="$(TestNuGetTargetMoniker)"
                                     TargetRuntime="$(TestNugetRuntimeId)"
                                     RuntimeFile="$(RuntimeIdGraphDefinitionFile)">
      <Output TaskParameter="CompileAssets" ItemName="Reference" />
      <Output TaskParameter="RuntimeAssets" ItemName="ReferenceCopyLocalPaths" />
    </GetApplicableAssetsFromPackages>
  </Target>

  <!-- Returns the set of files to be included in the nuget package
       with appropriate metadata.-->
  <Target Name="GetFilesToPackage"
          Returns="@(FilesToPackage)">
    <PropertyGroup>
      <PackagePath Condition="'$(PackagePath)' == ''">$(TargetPath)</PackagePath>
      <PackageIncludeDocs Condition="'$(PackageIncludeDocs)' == '' AND '$(IsReferenceAssembly)' == 'true'">true</PackageIncludeDocs>
      <PackageIncludeDocs Condition="'$(PackageIncludeDocs)' == '' AND '$(DocumentationFile)' != ''">true</PackageIncludeDocs>
    </PropertyGroup>

    <!-- Find a root directory that is an ancestor of every possible source file, including
         ones in bin and Tools. Allow configuration, otherwise prefer TFS root. -->
    <PropertyGroup>
      <ProjectRoot Condition="'$(ProjectRoot)'==''">$(SourcesRootPath)</ProjectRoot>
      <ProjectRoot Condition="'$(ProjectRoot)'==''">$(ProjectDir)</ProjectRoot>
      <ProjectRootLength>$(ProjectRoot.Length)</ProjectRootLength>
    </PropertyGroup>

    <!-- XmlDocFileRoot should be defined externally since these are currently not
         part of the corefx repo. -->
    <!-- This isn't a straight mapping to an algorithm using CultureInfo.
         There are special cases for en-US and zh-* so we manually list
         the mapping.-->
    <ItemGroup>
      <XmlDocFile Include="$(XmlDocFileRoot)/1028/$(TargetName).xml">
        <SubFolder>/zh-hant</SubFolder>
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/1031/$(TargetName).xml">
        <SubFolder>/de</SubFolder>
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/1033/$(TargetName).xml">
        <SubFolder />
        <!-- en docs go in root as neutral fall back -->
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/1036/$(TargetName).xml">
        <SubFolder>/fr</SubFolder>
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/1040/$(TargetName).xml">
        <SubFolder>/it</SubFolder>
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/1041/$(TargetName).xml">
        <SubFolder>/ja</SubFolder>
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/1042/$(TargetName).xml">
        <SubFolder>/ko</SubFolder>
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/1049/$(TargetName).xml">
        <SubFolder>/ru</SubFolder>
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/2052/$(TargetName).xml">
        <SubFolder>/zh-hans</SubFolder>
      </XmlDocFile>
      <XmlDocFile Include="$(XmlDocFileRoot)/3082/$(TargetName).xml">
        <SubFolder>/es</SubFolder>
      </XmlDocFile>
    </ItemGroup>

    <!-- currently behind a flag to avoid noise in the build -->
    <Warning Condition="'$(ValidateDocs)' == 'true' AND '$(PackageIncludeDocs)' == 'true' AND !Exists('%(XmlDocFile.Identity)')"
             Text="Documentation file %(XmlDocFile.Identity) was not found." />

    <!-- remove any missing docs-->
    <ItemGroup>
      <XmlDocFile Remove="@(XmlDocFile)" Condition="!Exists('%(XmlDocFile.Identity)')"/>
    </ItemGroup>

    <PropertyGroup>
      <!-- Desktop libraries that contain types in classic assemblies need to be included in ref
         so that the types unify with the classic assemblies from the targeting pack. -->
      <PackageDesktopAsRef Condition="'$(PackageDesktopAsRef)' == ''">$(IsPartialFacadeAssembly)</PackageDesktopAsRef>
      <PackageDesktopAsRef Condition="'$(PackageAsRefAndLib)' != ''">$(PackageAsRefAndLib)</PackageDesktopAsRef>

      <!-- Desktop libraries should also be packaged without a RID to work in packages.config projects -->
      <PackageDesktopAsLib Condition="'$(PackageDesktopAsLib)' == ''">true</PackageDesktopAsLib>

      <!-- A reference asset is any file contributed from a project that is contributing a reference,
           not just the file in the ref folder. -->
      <IsReferenceAsset Condition="'$(IsReferenceAsset)' == ''">$(IsReferenceAssembly)</IsReferenceAsset>
      <IsReferenceAsset Condition="'$(IsReferenceAsset)' == ''">false</IsReferenceAsset>
    </PropertyGroup>

    <!-- *** determine destination path for assets ***
         Order of precedence
           @(PackageDestination) - used verbatim, must set identity to path and TargetFramework to target moniker.

           $(PackageTargetFramework) & @(PackageTargetFramework) - combined to specify target monikers and optionally target runtime.  Path is calculated.
           $(NuGetTargetMoniker) - specifies target moniker if nothing else is specified.  Path is calculated.
    -->
    <GetPackageDestination Condition="'@(PackageDestination)' == ''"
                           PackageTargetFrameworks="$(PackageTargetFramework);@(PackageTargetFramework)"
                           PackageTargetRuntime="$(PackageTargetRuntime)"
                           NuGetTargetMoniker="$(NuGetTargetMoniker)"
                           IsReferenceAssembly="$(IsReferenceAssembly)"
                           PackageDesktopAsRef="$(PackageDesktopAsRef)"
                           PackageDesktopAsLib="$(PackageDesktopAsLib)"
                           SuppressPackageTargetFrameworkCompatibility="@(SuppressPackageTargetFrameworkCompatibility)">
      <Output TaskParameter="PackageDestinations" ItemName="PackageDestination" />
      <Output TaskParameter="IsReferenceAsset" PropertyName="IsReferenceAsset" />
    </GetPackageDestination>

    <!-- fail if not specified by the project  -->
    <Error Condition="'@(PackageDestination)' == ''" Text="Error could not determine packaging destination.  Please set either PackageTargetFramework property, PackageTargetFramework item, NuGetTargetMoniker property or PackageDestination item." />

    <!-- Be explicit about path seperators for the target path for source files. When building packages on *nix, the use of the DOS seperator
         was causing us to include source files in our packages in a folder called src\src, instead of them being stripped. -->
    <PropertyGroup>
      <SourceFileTargetPathPrefix Condition="'$(RunningOnUnix)' != 'true'">src\</SourceFileTargetPathPrefix>
      <SourceFileTargetPathPrefix Condition="'$(RunningOnUnix)' == 'true'">src/</SourceFileTargetPathPrefix>
    </PropertyGroup>

    <!-- *** include assets *** -->
    <ItemGroup>
      <!-- Include symbols output -->
      <SymbolFileToPackage Include="$(PackagePath.Replace('.dll', '.pdb'))" Condition="Exists($(PackagePath.Replace('.dll', '.pdb')))">
        <IsSymbolFile>true</IsSymbolFile>
      </SymbolFileToPackage>

      <!-- Include primary output -->
      <FilesToPackage Include="$(PackagePath);@(SymbolFileToPackage)">
        <AssemblyVersion>$(AssemblyVersion)</AssemblyVersion>
        <TargetFramework>%(PackageDestination.TargetFramework)</TargetFramework>
        <TargetPath>%(PackageDestination.Identity)</TargetPath>
        <IsReferenceAsset>$(IsReferenceAsset)</IsReferenceAsset>
      </FilesToPackage>

      <!-- Inlude any additional items if specified -->
      <FilesToPackage Include="@(AdditionalFileToPackage)">
        <TargetFramework>%(PackageDestination.TargetFramework)</TargetFramework>
        <TargetPath>%(PackageDestination.Identity)</TargetPath>
        <IsReferenceAsset>$(IsReferenceAsset)</IsReferenceAsset>
      </FilesToPackage>

      <!-- Include doc output if it isn't centrally authored -->
      <FilesToPackage Include="$(DocumentationFile)" Condition="'$(DocumentationFile)' != '' AND '@(XmlDocFile)' == '' AND '$(PackageIncludeDocs)' == 'true'">
        <TargetPath>%(PackageDestination.Identity)</TargetPath>
        <IsReferenceAsset>$(IsReferenceAsset)</IsReferenceAsset>
        <!-- intentionally omit TargetFramework: no dependencies for docs -->
      </FilesToPackage>

      <!-- Include pre-authored docs if available and required -->
      <FilesToPackage Include="@(XmlDocFile)" Condition="'$(PackageIncludeDocs)' == 'true'">
        <TargetPath>%(PackageDestination.Identity)</TargetPath>
        <IsReferenceAsset>$(IsReferenceAsset)</IsReferenceAsset>
        <!-- intentionally omit TargetFramework: no dependencies for docs -->
      </FilesToPackage>
      <FilesToPackage Condition="'%(FilesToPackage.SubFolder)' != ''">
        <TargetPath>%(TargetPath)%(FilesToPackage.SubFolder)</TargetPath>
      </FilesToPackage>

    </ItemGroup>
  </Target>
</Project>