Skip to content

Commit

Permalink
Ingest and import Windows Forms analyzer props
Browse files Browse the repository at this point in the history
Provide a mechanism to ingest Windows Forms specific analyzer props and
targets into Microsoft.NET.Sdk.WindowsDesktop from Windows Forms transport
package, and copy these files into `targets` folder of the SDK, so that
the props files are resolved and imported when a developer builds a Windows
Forms app.

In the end the new props file will end up in a location similar to this:
`C:\Program Files\dotnet\sdk\6.0.<version>\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\`.

This work relates to dotnet/designs#223, and acts
as a workaround until dotnet/designs#181 is
approved and implemented.
  • Loading branch information
RussKie committed Jun 7, 2021
1 parent 06d97b9 commit 0d8dd22
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectGuid>{440d06b8-e3de-4c0d-ad25-cd4f43d836e1}</ProjectGuid>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -25,4 +25,30 @@
<PackagingContent Include="targets\*" SubFolder="root\targets" />
<PackagingContent Include="useSharedDesignerContext.txt" SubFolder="root" />
</ItemGroup>

<!-- Windows Forms specific -->
<PropertyGroup>
<_WinFormsNuGetPath>$(PkgMicrosoft_Private_Winforms)</_WinFormsNuGetPath>
<_WinFormsContentPath>$(_WinFormsNuGetPath)\sdk\dotnet-wpf\*</_WinFormsContentPath>
</PropertyGroup>

<ItemGroup>
<PackagingContent Include="$(_WinFormsContentPath)" SubFolder="root\targets" />
</ItemGroup>

<!--
This target *only* validates the content of Microsoft.Private.Winforms NuGet package
to ensure we correctly import and reference props and targets.
-->
<Target Name="_EnsureWindowsFormsPackagingContent" BeforeTargets="IdentifyPackageAssets">
<Error Text="Unable to resolve path to Microsoft.Private.Winforms NuGet package. Is %24(PkgMicrosoft_Private_Winforms) defined?"
Condition="'$(_WinFormsNuGetPath)' == ''"/>

<ItemGroup>
<_WinFormsContent Include="$(_WinFormsContentPath)" />
</ItemGroup>

<Error Text="Microsoft.Private.Winforms NuGet package contains no content. Is this expected?"
Condition="@(_WinFormsContent->Count()) == 0"/>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,7 @@
<SupportedTargetFramework Remove="@(_UnsupportedNETCoreAppTargetFramework);@(_UnsupportedNETStandardTargetFramework);@(_UnsupportedNETFrameworkTargetFramework)" />
</ItemGroup>

<!-- Import Windows Forms specific props -->
<Import Project="System.Windows.Forms.Analyzers.props" />

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@
<!-- Import WPF Build logic only when we don't import NETFX's WinFX targets -->
<Import Project="Microsoft.WinFX.targets" Condition="'$(ImportFrameworkWinFXTargets)' != 'true'"/>

<!-- Import Windows Forms specific targets -->
<Import Project="System.Windows.Forms.Analyzers.targets" />

</Project>

0 comments on commit 0d8dd22

Please sign in to comment.