summaryrefslogtreecommitdiff
path: root/.packages/microsoft.dotnet.arcade.sdk/1.0.0-beta.20113.5/tools/VisualStudio.VsixBuild.targets
blob: 093a2c34b57d42a201c2b1993bfa06f3a1aa21b5 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?xml version="1.0" encoding="utf-8"?>
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Project>

  <!--
    There are three kinds of projects that use targets defined here:
      1) Projects using VS SDK to build VSIX packages:       IsVsixProject == true, CreateVsixContainer == true
      2) Projects using VS SDK to generate .pkgdef files:    IsVsixProject == true, GeneratePkgDefFile == true
      3) Projects that pack Willow packages (swix):          SwrFile items present
      
    The main targets in this file are:
      1) FinalizeInsertionVsixFiles
         Removes Experimental flag from VSIXes that comprise VS insertion components and copies the updated VSIXes to VSSetup\Insertion directory.
         
         Writes a stub file to component intermediate directory for each VSIX project that belongs to this component.
         This stub file is used by VisualStudio.Insertion.proj to compose insertion components.
         
      2) SwixBuild
         Builds a Willow component out of SwrFiles.
         Writes a stub file to component intermediate directory.
  -->

  <PropertyGroup>
    <_VisualStudioBuildTasksAssembly>$(NuGetPackageRoot)microsoft.dotnet.build.tasks.visualstudio\$(MicrosoftDotNetBuildTasksVisualStudioVersion)\tools\net472\Microsoft.DotNet.Build.Tasks.VisualStudio.dll</_VisualStudioBuildTasksAssembly>
  </PropertyGroup>

  <UsingTask TaskName="Microsoft.DotNet.Build.Tasks.VisualStudio.FinalizeInsertionVsixFile" AssemblyFile="$(_VisualStudioBuildTasksAssembly)" />

  <PropertyGroup>
    <!--
      TODO: Currently we need to erase Experimental flag from VSIXes that are inserted into VS.
      The build produces VSIXes with the flag on and FinalizeInsertionVsixFiles target then makes a copy to VisualStudioSetupInsertionPath
      and updates the manifest.
      Instead the VSIX installer should allow to override the experimental flag, so that we can only produce a single VSIX and
      build VSIX that is going to be inserted into VS directly to directory $(VisualStudioSetupInsertionPath).
    -->
    <_TargetVsixContainerDir>$(VisualStudioSetupOutputPath)</_TargetVsixContainerDir>

    <TargetVsixContainerName Condition="'$(TargetVsixContainerName)' == ''">$(TargetName).vsix</TargetVsixContainerName>
    <TargetVsixContainer Condition="'$(TargetVsixContainer)' == ''">$(_TargetVsixContainerDir)$(TargetVsixContainerName)</TargetVsixContainer>

    <DeployExtension Condition="'$(DeployProjectOutput)' == 'true'">true</DeployExtension>
  </PropertyGroup>

  <PropertyGroup Condition="'$(VisualStudioInsertionComponent)' != ''">
    <_ComponentIntermediateDir>$(VisualStudioSetupIntermediateOutputPath)$(VisualStudioInsertionComponent)\</_ComponentIntermediateDir>

    <IsProductComponent>true</IsProductComponent>

    <Ngen Condition="'$(Ngen)' == ''">true</Ngen>
    <NgenArchitecture Condition="'$(NgenArchitecture)' == ''">All</NgenArchitecture>
    <NgenPriority Condition="'$(NgenPriority)' == ''">3</NgenPriority>
  </PropertyGroup>

  <ItemGroup Condition="'$(VisualStudioInsertionComponent)' != ''">
    <ProjectReference Update="@(ProjectReference)">
      <Ngen Condition="'%(Ngen)' == ''">true</Ngen>
      <NgenArchitecture Condition="'%(NgenArchitecture)' == '' and '%(Ngen)' != 'false'">All</NgenArchitecture>
      <NgenPriority Condition="'%(NgenPriority)' == '' and '%(Ngen)' != 'false'">3</NgenPriority>
    </ProjectReference>
  </ItemGroup>

  <!--
    Assemblies that are NGEN'd should be loaded to Load context, otherwise NGEN would not work.
    UseCodebase causes assemblies to be loaded to LoadFrom context, so it's incompatible with NGEN setting.
  -->
  <Target Name="_WarnOnUsingCodebaseWithNgen" 
          BeforeTargets="GeneratePkgDef" 
          Condition="'$(Ngen)' == 'true' and '$(UseCodebase)' == 'true'">
    <Warning Text="UseCodebase should not be true for VSIX project that turns NGEN on." />
  </Target>

  <!--
    Calculate name of a stub file that will be saved to ComponentIntermediateDir (Setup.obj subdirectory for the target insertion component).
  -->
  <Target Name="_SetStubFileNameFromManifest">
    <PropertyGroup>
      <_VsxXmlNamespace>&lt;Namespace Prefix='vsx' Uri='http://schemas.microsoft.com/developer/vsx-schema/2011'/&gt;</_VsxXmlNamespace>
    </PropertyGroup>

    <!--
      Read package id from the extension.vsixmanifest file. VS SDK doesn't expose this value in any msbuild property.
    -->
    <XmlPeek Namespaces="$(_VsxXmlNamespace)"
             XmlInputPath="$(IntermediateVsixManifest)"
             Query="/vsx:PackageManifest/vsx:Metadata/vsx:PackageId/text()">
      <Output TaskParameter="Result" PropertyName="_VsixPackageId" />
    </XmlPeek>

    <XmlPeek Namespaces="$(_VsxXmlNamespace)"
             XmlInputPath="$(IntermediateVsixManifest)"
             Query="/vsx:PackageManifest/vsx:Metadata/vsx:Identity/@Id"
             Condition="'$(_VsixPackageId)' == ''">
      <Output TaskParameter="Result" PropertyName="_VsixPackageId" />
    </XmlPeek>

    <Error Text="Unable to determine VSIX package id for project '$(MSBuildProjectFullPath)'." Condition="'$(_VsixPackageId)' == ''"/>

    <PropertyGroup>
      <_PackageStubFile>$(_ComponentIntermediateDir)$(_VsixPackageId).stub</_PackageStubFile>
    </PropertyGroup>
  </Target>

  <!--
    Create VSIX container directory.
  -->
  <Target Name="_MakeTargetVsixContainerDir"
          BeforeTargets="CreateVsixContainer"
          Condition="'$(CreateVsixContainer)' == 'true'"
          Outputs="$(_TargetVsixContainerDir)">

    <MakeDir Directories="$(_TargetVsixContainerDir)" />
  </Target>

  <!--
    Create VSIX container directory and a stub file that can be used in Pack phase to identify what VSIXes belong to the component.
  -->
  <Target Name="_WriteComponentStubFile" Outputs="$(_PackageStubFile)">
    <Error Text="VisualStudioInsertionComponent property must only be set for projects with extension.vsixmanifest or SWR files." Condition="'$(_PackageStubFile)' == ''"/>

    <MakeDir Directories="$(_ComponentIntermediateDir)" />
    <WriteLinesToFile File="$(_PackageStubFile)" Lines="$(TargetVsixContainerName)/$(VsixVersion)" Overwrite="true" />

    <ItemGroup>
      <FileWrites Include="$(_PackageStubFile)"/>
    </ItemGroup>
  </Target>

  <!--
    Currently we need to erase Experimental flag from VSIXes that are inserted into VS.
    The build produces VSIXes to VisualStudioSetupPath that need this treatment.
    This task copies them to VisualStudioSetupInsertionPath and removes the flag from the manifest.
    VSIX files that are already in VisualStudioSetupInsertionPath are already non-experimental.
  -->

  <Target Name="_CalculateFinalizeInsertionVsixFilesInputsOutputs"
          DependsOnTargets="_SetStubFileNameFromManifest">
    <PropertyGroup>
      <_JsonFileName>$(_VsixPackageId).json</_JsonFileName>
    </PropertyGroup>

    <ItemGroup>
      <_FinalizeInsertionVsixFilesInputs Include="$(VisualStudioSetupOutputPath)$(TargetVsixContainerName)" />
      <_FinalizeInsertionVsixFilesInputs Include="$(VisualStudioSetupOutputPath)$(_JsonFileName)" />

      <_FinalizeInsertionVsixFilesOutputs Include="$(VisualStudioSetupInsertionPath)$(TargetVsixContainerName)" />
      <_FinalizeInsertionVsixFilesOutputs Include="$(VisualStudioSetupInsertionPath)$(_JsonFileName)" />
    </ItemGroup>
  </Target>

  <Target Name="FinalizeInsertionVsixFiles"
          AfterTargets="Build"
          DependsOnTargets="CreateVsixContainer;_CalculateFinalizeInsertionVsixFilesInputsOutputs;_WriteComponentStubFile"
          Condition="'$(CreateVsixContainer)' == 'true' and '$(VisualStudioInsertionComponent)' != ''"
          Inputs="@(_FinalizeInsertionVsixFilesInputs)"
          Outputs="@(_FinalizeInsertionVsixFilesOutputs)">

    <MakeDir Directories="$(VisualStudioSetupInsertionPath)"/>

    <Copy SourceFiles="@(_FinalizeInsertionVsixFilesInputs)" DestinationFolder="$(VisualStudioSetupInsertionPath)" />

    <Microsoft.DotNet.Build.Tasks.VisualStudio.FinalizeInsertionVsixFile VsixFilePath="$(VisualStudioSetupInsertionPath)$(TargetVsixContainerName)" />

    <ItemGroup>
      <FileWrites Include="@(_FinalizeInsertionVsixFilesOutputs)"/>
    </ItemGroup>
  </Target>

  <!--
    Build Willow VSIX from SWR files.
  -->
  <Target Name="SwixBuild"
          DependsOnTargets="_CalculateSwixBuildOutputs;_WriteComponentStubFile"
          AfterTargets="Build"
          Outputs="$(_SwixBuildOutputs)"
          Condition="'$(IsSwixProject)' == 'true'">

    <Error Text="Visual Studio insertion component must either have extension.vsixmanifest or specify SwrFile items"
           Condition="'@(SwrFile)' == ''" />

    <PropertyGroup>
      <_SwrProperties>@(SwrProperty)</_SwrProperties>
      <_SwrFiles>@(SwrFile->'%(FullPath)')</_SwrFiles>
    </PropertyGroup>

    <ItemGroup>
      <_SwixArgs Include="SwrProperties=$([MSBuild]::Escape($(_SwrProperties)))"/>
      <_SwixArgs Include="SwrFiles=$([MSBuild]::Escape($(_SwrFiles)))"/>
      <_SwixArgs Include="SwrPackageName=$(_VsixPackageId)"/>
      <_SwixArgs Include="IntermediateOutputPath=$(IntermediateOutputPath)"/>
      <_SwixArgs Include="SwixBuildPath=$(NuGetPackageRoot)microbuild.plugins.swixbuild\$(MicroBuildPluginsSwixBuildVersion)\"/>
    </ItemGroup>

    <MSBuild Projects="$(MSBuildThisFileDirectory)VisualStudio.SetupPackage.swixproj" Properties="@(_SwixArgs)" Targets="Build"/>

    <Copy SourceFiles="$(IntermediateOutputPath)$(TargetVsixContainerName);$(IntermediateOutputPath)$(_JsonFileName)"
          DestinationFolder="$(VisualStudioSetupInsertionPath)" />

    <ItemGroup>
      <FileWrites Include="@(_SwixBuildOutputs)"/>
    </ItemGroup>
  </Target>

  <Target Name="_CalculateSwixBuildOutputs">
    <PropertyGroup>
      <_VsixPackageId>$([System.IO.Path]::GetFileNameWithoutExtension($(TargetVsixContainerName)))</_VsixPackageId>
      <_PackageStubFile>$(_ComponentIntermediateDir)$(_VsixPackageId).stub</_PackageStubFile>
      <_JsonFileName>$(_VsixPackageId).json</_JsonFileName>
    </PropertyGroup>

    <ItemGroup>
      <_SwixBuildOutputs Include="$(VisualStudioSetupInsertionPath)$(TargetVsixContainerName)" />
      <_SwixBuildOutputs Include="$(VisualStudioSetupInsertionPath)$(_JsonFileName)" />
    </ItemGroup>
  </Target>

  <!--
    This is a workaround for allowing neutral CTO resource produced from *.vsct to go in the main assembly.

    We move the neutral *.cto file to be categorized as WithCulture=true,Culture=en to prevent the tools from falsely reporting:
      error VSSDK1006: Two CTO files have the same Menus.ctmenu resource name.

     Note that this categorization does not apply to the items that actually produce the .resources.dll and so it will
     not cause an English satellite to be generated.

     The documented way around this is to put all resources (including neutral/en) in satellites:
       https://msdn.microsoft.com/en-us/library/ee943168.aspx

       However, that has consequences we do not want:
        - It breaks resx code-gen to *.designer.cs
        - It causes extra dll loads in en case
        - If we ever split satellites in to language packs, the english fallback satellites would become a special case.
  -->
  <Target Name="AssignEnCultureToNeutralCto" BeforeTargets="MergeCtoResource">
    <ItemGroup>
      <_GeneratedCTOFilesWithCulture Include="@(_GeneratedCTOFilesWithNoCulture)">
        <Culture>en</Culture>
        <WithCulture>true</WithCulture>
      </_GeneratedCTOFilesWithCulture>
      <_GeneratedCTOFilesWithNoCulture Remove="@(_GeneratedCTOFilesWithNoCulture)" />
      <_ResourcesToMergeWithCTOWithCultureMetadata Condition="'%(WithCulture)' != 'true'">
        <Culture>en</Culture>
        <WithCulture>true</WithCulture>
      </_ResourcesToMergeWithCTOWithCultureMetadata>
    </ItemGroup>
  </Target>

  <!--
    VSSDK is needed in projects generating VSIX packages or pkgdef files.
  -->
  <Import Project="VisualStudio.ImportSdk.targets" Condition="'$(VSToolsPath)' != '' and ('$(IsVsixProject)' == 'true' or '$(GeneratePkgDefFile)' == 'true')" />

  <!--
    Support for templates.
  -->
  <Target Name="_GetVsixTemplateItems" DependsOnTargets="ZipProjects;ZipItems" Condition="'@(VSTemplate)' != ''">
    <ItemGroup>
      <VSIXSourceItem Include="@(IntermediateZipItem)">
        <VSIXSubPath>%(IntermediateZipItem.Filename)\%(IntermediateZipItem.Language)\%(IntermediateZipItem.OutputSubPath)\%(IntermediateZipItem.Culture)</VSIXSubPath>
      </VSIXSourceItem>
      <VSIXSourceItem Include="@(IntermediateZipProject)">
        <VSIXSubPath>%(IntermediateZipProject.Filename)\%(IntermediateZipProject.Language)\%(IntermediateZipProject.OutputSubPath)\%(IntermediateZipProject.Culture)</VSIXSubPath>
      </VSIXSourceItem>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <GetVsixSourceItemsDependsOn>$(GetVsixSourceItemsDependsOn);_GetVsixTemplateItems</GetVsixSourceItemsDependsOn>
  </PropertyGroup>
</Project>