sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Migrating C++/CLI project throws compiler warning C4945

Open NavrimCPP opened this issue 2 years ago • 6 comments

The Solution contains a combination of C#, C++/CLI and C++ projects. I followed the guide for migrating C++/CLI projects.(https://learn.microsoft.com/en-us/dotnet/core/porting/cpp-cli.)

I need to specify the FrameworkReference for WPF (<FrameworkReferenceInclude="Microsoft.WindowsDesktop.App.WPF" />).

When compiling, I get many C4945 warnings. Because we have TreatWarningsAsErrors enabled, the project can't be compiled. Disabling TreatWarningsAsErrors or disabling the C4945 warnings is not a permanent solution for us.

Example C4945 warning: warning C4945: 'BulletChrome': cannot import symbol from 'C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.14\ref\net6.0\PresentationFramework.Aero2.dll': as 'Microsoft::Windows::Themes::BulletChrome' has already been imported from another assembly 'PresentationFramework.Aero'

The warnings can be easily reproduced

  • Create a new C++/CLI(.NET) Project

  • Add the following to the .vcxproj file

    <ItemGroup>
        <FrameworkReference Include="Microsoft.WindowsDesktop.App.Wpf" />
    </ItemGroup>
  • And Compile

What can I do to stop these warnings from occurring?

Previously, I was able to reference explicitly, e.g.

<ItemGroup>
    <Reference Include="PresentationCore" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
</ItemGroup>

NavrimCPP avatar Mar 10 '23 12:03 NavrimCPP

@jaredpar any pointers on those compiler warnings in a c++/CLI app?

marcpopMSFT avatar Mar 14 '23 18:03 marcpopMSFT

@dangrif have any pointers here?

jaredpar avatar Mar 14 '23 18:03 jaredpar

Hi, is there any new information about the problem?

NavrimCPP avatar Jun 14 '23 06:06 NavrimCPP

We encountered the same problem. Is there any news regarding the problem or advice on how to work around the error?

I have created a minimal project to reproduce the warning and it is sufficient to simply reference the framework to trigger the warning: https://github.com/Wittenborn/cpp-cli-warning-C4945/

Wittenborn avatar May 16 '24 11:05 Wittenborn

Same problem here. Any news?

as32 avatar Aug 18 '24 16:08 as32

Same problem over here. However I'm targeting .net 8 instead of .net 6. Everything else stays the same.

sensslen avatar Aug 30 '24 06:08 sensslen

Same problem here.

santiagoIT avatar Sep 18 '24 15:09 santiagoIT

Same problem here too.

rfvan avatar Oct 11 '24 23:10 rfvan

exact same problem occurs in C++/CLI for .NET 9 as well.

gazette2 avatar Nov 25 '24 13:11 gazette2

same problem

as32 avatar Jan 03 '25 09:01 as32