ollimexx
ollimexx

Reputation: 33

problems migrating c++/cli project from .net 4.7 to .netcore 3.1

I am migrating a wpf .net 4.7 Solution to .net core 3.1 I'm working with Visual Studio 16.6.3. the wpf project is compiling fine with .net core. but a depending c++/cli Project does not compile. I changed the .vcxproject according to this https://learn.microsoft.com/de-de/dotnet/core/porting/cpp-cli. the vcxproject now looks like:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>...</ProjectGuid>
    <Keyword></Keyword>
    <RootNamespace>XY</RootNamespace>
    <WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>MultiByte</CharacterSet>
    <CLRSupport>NetCore</CLRSupport>
    <VCToolsVersion>14.26.28801</VCToolsVersion>
  </PropertyGroup>
 
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>false</LinkIncremental>
    <OutDir>$(ProjectDir)..\..\build\</OutDir>
    <IntDir>$(ProjectDir)..\..\tmp\$(ProjectName)\</IntDir>
    <EnableManagedIncrementalBuild>true</EnableManagedIncrementalBuild>
    <IncludePath>$(IncludePath)</IncludePath>
    <IgnoreImportLibrary>false</IgnoreImportLibrary>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <!-- <LinkIncremental>false</LinkIncremental>    -->
    <LinkIncremental>true</LinkIncremental>
    <OutDir>$(ProjectDir)..\..\build\</OutDir>
    <IntDir>$(ProjectDir)..\..\tmp\$(ProjectName)\</IntDir>
    <EnableManagedIncrementalBuild>true</EnableManagedIncrementalBuild>
    <IncludePath>$(IncludePath)</IncludePath>
    <IgnoreImportLibrary>false</IgnoreImportLibrary>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;WIN32;%(PreprocessorDefinitions);WS_CPLUSPLUS</PreprocessorDefinitions>
      <ConformanceMode>false</ConformanceMode>
      <PrecompiledHeaderFile>
      </PrecompiledHeaderFile>
      <AdditionalIncludeDirectories></AdditionalIncludeDirectories>
      <AdditionalUsingDirectories>
      </AdditionalUsingDirectories>
      <LanguageStandard>stdcpp17</LanguageStandard>
      <CompileAsManaged>true</CompileAsManaged>
      <CallingConvention>
      </CallingConvention>
      <UndefinePreprocessorDefinitions>
      </UndefinePreprocessorDefinitions>
      <MultiProcessorCompilation>true</MultiProcessorCompilation>
      <LanguageStandard>stdcpp17</LanguageStandard>
      <DiagnosticsFormat>Classic</DiagnosticsFormat>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>DebugFull</GenerateDebugInformation>
      <EnableUAC>false</EnableUAC>
      <AdditionalLibraryDirectories></AdditionalLibraryDirectories>
      <AdditionalDependencies>opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;gdiplus.lib;d2d1.lib;%(AdditionalDependencies);WebServices.lib</AdditionalDependencies>
      <PreventDllBinding>false</PreventDllBinding>
      <Profile>false</Profile>
      <AdditionalOptions></AdditionalOptions>
    </Link>
  </ItemDefinitionGroup>
 

  <ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
  </ItemGroup>
  
  ...
</Project>

According to the above link, the System References should be removed and are loaded automatically by vs due to <CLRSupport>NetCore</CLRSupport>

but now previously fine compiled CPP files are not compiling anymore with the following error

c:\program files\dotnet\packs\microsoft.netcore.app.ref\3.1.0\ref\netcoreapp3.1\mscorlib.dll : fatal error C1001: Internal compiler error. (compiler file 'msc1.cpp', line 1533)

even if i add the simplest cpp file and compile it with right click-compile the same error occurs, so it not really depends on the cpp code

When I hover over the first char from CPP files in the editor, it shows 'System' not loaded from default assemblies

the cli project was compiling fine before migrating.

Upvotes: 2

Views: 2485

Answers (1)

Mr Qian
Mr Qian

Reputation: 23715

problems migrating c++/cli project from .net 4.7 to .netcore 3.1

I have tested in my side : migrate a net framework clr project into net core clr project by the guidance document without any errors.

So please try the following suggestions:

Suggestion

Please check to make sure you use these properties in xxx.vcxproj file instead.

<TargetFramework>netcoreapp3.1</TargetFramework>
<CLRSupport>NetCore</CLRSupport> //there are four parts that need to be edited.

1) close VS Instance, delete .vs hidden folder, output folders like Debug or x64(both on solution folder and project folder)

2) Right-click on the c++ project-->Properties-->C/C++-->Optimization-->set Optimization to Disabled(/Od)

Changing Link Time Code Generation to /LTCG by Project Properties --> Linker --> Optimization.

Besides, please try to create a new default C++ Clr Net Core project and then test whether it can be built successfully.

And if so, you can try to migrate your old project into the new project.

In addition, you can share a minimal, reproducible sample with us so that we can troubleshoot your issue more quickly.

====================

Update

The reason is that you have use CompileAsManaged xml node in your xxx.vcxproj file, and for your net core clr project does not need that node. With it, you lose the assembly reference.

Actually, that node conflicts with your project due to some reasons whether its value is true or false.

Solution

Delete this node in xxx.vcxproj file.

<CompileAsManaged>true</CompileAsManaged>

Then you will built your project successfully as I did.

Upvotes: 8

Related Questions