Skip to content

Commit d49e8c5

Browse files
committed
Import Windows Forms related props and targets into Windows Desktop
* Establish a mechanism to import Windows Forms related functionality into Windows Desktop SDK via the Windows Forms transport package. * Add a basic validation of the content of the shipping package in .\eng\WindowsFormsImports.targets.
1 parent df6ea7a commit d49e8c5

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

eng/WindowsFormsImports.targets

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<_WindowsFormsNuGetPath>$(PkgMicrosoft_Private_Winforms)</_WindowsFormsNuGetPath>
5+
</PropertyGroup>
6+
7+
<!--
8+
============================================================
9+
_ValidateWindowsFormsPackagingContent
10+
Validates the content of Microsoft.Private.Winforms NuGet package
11+
to ensure we correctly import and reference props and targets.
12+
============================================================
13+
-->
14+
<Target Name="_ValidateWindowsFormsPackagingContent">
15+
<PropertyGroup>
16+
<_WindowsFormsContentPath>$(_WindowsFormsNuGetPath)\sdk\dotnet-wpf\*</_WindowsFormsContentPath>
17+
<_WindowsFormsRequiredFileName>Microsoft.NET.SDk.WindowsDesktop.WindowsForms</_WindowsFormsRequiredFileName>
18+
</PropertyGroup>
19+
20+
<Error Text="Unable to resolve path to Microsoft.Private.Winforms NuGet package. Is %24(PkgMicrosoft_Private_Winforms) defined?"
21+
Condition="'$(_WindowsFormsNuGetPath)' == ''"/>
22+
23+
<ItemGroup>
24+
<!-- Enumerate all transported files -->
25+
<_WindowsFormsContent Include="$(_WindowsFormsContentPath)" />
26+
<!-- ...and verify Microsoft.NET.SDk.WindowsDesktop.WindowsForms.props/.targets are present -->
27+
<_WindowsFormsContentFiles Include="@(_WindowsFormsContent->'%(FileName)%(Extension)')"
28+
Condition=" '%(FileName)%(Extension)' == '$(_WindowsFormsRequiredFileName).props'
29+
or '%(FileName)%(Extension)' == '$(_WindowsFormsRequiredFileName).targets' "/>
30+
</ItemGroup>
31+
32+
<!-- Fail if the required files are missing -->
33+
<Error Text="Microsoft.Private.Winforms NuGet package does not contain $(_WindowsFormsRequiredFileName).props or $(_WindowsFormsRequiredFileName).targets"
34+
Condition="@(_WindowsFormsContentFiles->Count()) != 2"/>
35+
</Target>
36+
37+
38+
<!--
39+
============================================================
40+
_IdentifyWindowsFormsPackageAssets
41+
Add props/targets shipped by Windows Forms to the collection of files that get packaged
42+
in to Microsoft.NET.Sdk.WindowsDesktop.<configuration>.<version>.nupkg.
43+
============================================================
44+
-->
45+
<Target Name="_IdentifyWindowsFormsPackageAssets" BeforeTargets="IdentifyPackageAssets" DependsOnTargets="_ValidateWindowsFormsPackagingContent">
46+
<ItemGroup>
47+
<PackagingContent Include="$(_WindowsFormsContentPath)" SubFolder="root\targets" />
48+
</ItemGroup>
49+
</Target>
50+
51+
</Project>

packaging/Microsoft.NET.Sdk.WindowsDesktop/Microsoft.NET.Sdk.WindowsDesktop.ArchNeutral.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
23
<PropertyGroup>
34
<ProjectGuid>{440d06b8-e3de-4c0d-ad25-cd4f43d836e1}</ProjectGuid>
45
<TargetFramework>net6.0</TargetFramework>
@@ -25,4 +26,8 @@
2526
<PackagingContent Include="targets\*" SubFolder="root\targets" />
2627
<PackagingContent Include="useSharedDesignerContext.txt" SubFolder="root" />
2728
</ItemGroup>
29+
30+
<!-- Windows Forms specific -->
31+
<Import Project="$(RepositoryEngineeringDir)WindowsFormsImports.targets" />
32+
2833
</Project>

packaging/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,11 @@
161161
<SupportedTargetFramework Remove="@(_UnsupportedNETCoreAppTargetFramework);@(_UnsupportedNETStandardTargetFramework);@(_UnsupportedNETFrameworkTargetFramework)" />
162162
</ItemGroup>
163163

164+
<!--
165+
Import Windows Forms props.
166+
These come via the Windows Forms transport package, that can be found under
167+
https://github.com/dotnet/winforms/tree/main/pkg/Microsoft.Private.Winforms/sdk
168+
-->
169+
<Import Project="Microsoft.NET.SDk.WindowsDesktop.WindowsForms.props" />
170+
164171
</Project>

packaging/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,11 @@
155155
<!-- Import WPF Build logic only when we don't import NETFX's WinFX targets -->
156156
<Import Project="Microsoft.WinFX.targets" Condition="'$(ImportFrameworkWinFXTargets)' != 'true'"/>
157157

158+
<!--
159+
Import Windows Forms targets.
160+
These come via the Windows Forms transport package, that can be found under
161+
https://github.com/dotnet/winforms/tree/main/pkg/Microsoft.Private.Winforms/sdk
162+
-->
163+
<Import Project="Microsoft.NET.SDk.WindowsDesktop.WindowsForms.targets" Condition="'$(UseWindowsForms)' == 'true'"/>
164+
158165
</Project>

0 commit comments

Comments
 (0)