Open PDeets opened 2 weeks ago
I worked around the issue by adding this to my project:
<Target Name="FixPublicContractTypes" AfterTargets="CsWinRTGenerateProjection">
<!-- Workaround for https://github.com/microsoft/CsWinRT/issues/1668. Windows.Foundation.cs is generated
with two public enums that should be internal. This target switches them to be internal. -->
<PropertyGroup>
<FileToFix>$(CsWinRTGeneratedFilesDir)Windows.Foundation.cs</FileToFix>
</PropertyGroup>
<WriteLinesToFile File="$(FileToFix)" Lines="$([System.IO.File]::ReadAllText($(FileToFix)).Replace('public enum', 'internal enum'))" Overwrite="true" Encoding="Unicode" />
</Target>
Describe the bug I'm using embedded mode to call a WinRT API where I have a NuGet with the winmd, but not an interop assembly. Everything builds OK, but the generated source uses "public" for contract types. For example, in Windows.Foundation.cs, I see this:
The issue is in the
write_contract
function in src/cswinrt/code_writers.h. The otherwrite_*
functions use theinternal_accessibility
to pick between "internal" and "public", butwrite_contract
just uses "public" all the time.This makes it so if I have two assemblies both using C#/WinRT embedded mode and one depends on the other, there are build warnings about FoundationContract being defined in two places.
To Reproduce
Use C#/WinRT's embedded mode while including Windows.Foundation.
Expected behavior No WinRT types are exposed as public from the generated assembly.
Actual Behavior
Windows.Foundation.FoundationContract
is exposed as public from the generated assembly.Version Info I'm using version 2.0.7 of the Microsoft.Windows.CsWinRT NuGet.