Skip to content

Commit 296220d

Browse files
Sergio0694Copilot
andcommitted
Run CsWin32 generator as a build task and drop the IL2050 suppression
Bump CsWin32 to 0.3.298 and set CsWin32RunAsBuildTask=true centrally so the generator runs as an MSBuild build task. This improves IntelliSense performance and emits trim-safe/AOT-safe interop code, which makes the previous IL2050 suppression in UnitTest unnecessary (CA1420 is kept, as the COM 'object' parameter of CoRegisterClassObject still requires runtime marshalling). Also simplify the CsWin32 PackageReference in UnitTest and OOPExe to PrivateAssets=all. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9043c1b commit 296220d

4 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@
119119
files aren't included. Once that issue is fixed, this should be restricted to published projects only.
120120
-->
121121
<GenerateDocumentationFile Condition="'$(IsPublicProject)' == 'true'">true</GenerateDocumentationFile>
122+
123+
<!--
124+
Run the CsWin32 source generator as an MSBuild build task instead of an in-process Roslyn source
125+
generator. This improves IntelliSense performance and lets CsWin32 generate trim-safe and AOT-safe
126+
interop code. It's a no-op for projects that don't reference CsWin32.
127+
-->
128+
<CsWin32RunAsBuildTask>true</CsWin32RunAsBuildTask>
122129
</PropertyGroup>
123130

124131
<!-- Set overrides to point to folder where they are built in solution -->

src/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<PackageVersion Include="Microsoft.VCRTForwarders.140" Version="1.1.0" />
2828
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.3179.45" />
2929
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
30-
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.1.635-beta" />
30+
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.298" />
3131
<PackageVersion Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
3232
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="[10.0.22000.194]" />
3333
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.18362.2005" />

src/Tests/OOPExe/OOPExe.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.Windows.CsWin32">
19-
<PrivateAssets>all</PrivateAssets>
20-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21-
</PackageReference>
18+
<PackageReference Include="Microsoft.Windows.CsWin32" PrivateAssets="all" />
2219
</ItemGroup>
2320

2421
<ItemGroup>

src/Tests/UnitTest/UnitTest.csproj

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
<NoWarn>$(NoWarn);CA1416</NoWarn>
3030

3131
<!--
32-
The CsWin32 source generator emits a 'CoRegisterClassObject' P/Invoke (in 'Ole32') that uses COM
33-
marshalling, which trips 'IL2050' (COM interop correctness under trimming) and 'CA1420' (requires
34-
runtime marshalling, which is disabled repo-wide). This is generated code we don't control, so
35-
suppress both here.
32+
The CsWin32-generated 'CoRegisterClassObject' P/Invoke (in 'Ole32') takes a COM 'object' parameter
33+
whose marshalling requires runtime marshalling, which is disabled repo-wide, so it trips 'CA1420'.
34+
This is generated code we don't control, so suppress it here. (With 'CsWin32RunAsBuildTask=true' the
35+
generator now emits trim-safe/AOT-safe code, so the previous 'IL2050' suppression is no longer needed.)
3636
-->
37-
<NoWarn>$(NoWarn);IL2050;CA1420</NoWarn>
37+
<NoWarn>$(NoWarn);CA1420</NoWarn>
3838
<SelfContained>true</SelfContained>
3939
<CsWinRTEnabled>false</CsWinRTEnabled>
4040
<OutputType>exe</OutputType>
@@ -72,10 +72,7 @@
7272
<!--<ProjectReference Include="..\OOPExe\OOPExe.csproj" />-->
7373

7474
<PackageReference Include="Microsoft.VCRTForwarders.140" />
75-
<PackageReference Include="Microsoft.Windows.CsWin32">
76-
<PrivateAssets>all</PrivateAssets>
77-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
78-
</PackageReference>
75+
<PackageReference Include="Microsoft.Windows.CsWin32" PrivateAssets="all" />
7976
<PackageReference Include="Newtonsoft.Json" />
8077
<ProjectReference Include="..\..\Authoring\WinRT.SourceGenerator2\WinRT.SourceGenerator2.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" SetPlatform="Platform=AnyCPU" />
8178
</ItemGroup>

0 commit comments

Comments
 (0)