微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C++/CLI 库 .NETFramework 到 .Net Standard

如何解决C++/CLI 库 .NETFramework 到 .Net Standard

以下是 C++/CLI 应用程序的 VS2019 项目文件。目标是将其从 .Net Framework 升级为 .Net Standard 2.0。

在我开始处理整个 log4net 参考之前,它一直在用 .Net Core 5.0 编译和链接 find。换句话说,.Net Core 5.0 并没有试图将 log4net 接口传递到这个库中,一切都很好。一旦传入,就会出现错误。旧的 log4net 参考已从该项目中撤出并替换为 .Net Standard 2.0。现在有这个错误

warning MSB3268: The primary reference "log4net" Could not be resolved because it has an indirect dependency on the framework assembly "netstandard,Version=2.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51" which Could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem,either remove the reference "log4net" or retarget your application to a framework version which contains "netstandard,PublicKeyToken=cc7b13ffcd2ddd51".
AFile.h(3): error C2871: 'log4net': a namespace with this name does not exist

我只是在项目文件中没有看到任何对 .Net Framework 或 .Net Standard 的引用。我该如何解决这个问题?

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" Toolsversion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{9FAC29B5-62B2-4323-9469-921B467C8433}</ProjectGuid>
    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
    <RootNamespace>theCppCliLibraryName</RootNamespace>
    <Keyword>ManagedCProj</Keyword>
    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <PlatformToolset>v140_xp</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <Clrsupport>true</Clrsupport>
    <WholeProgramOptimization>true</WholeProgramOptimization>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <PlatformToolset>v140_xp</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <Clrsupport>true</Clrsupport>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="propertysheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="propertysheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <_ProjectFiLeversion>14.0.25431.1</_ProjectFiLeversion>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <OutDir>$(SolutionDir)$(Configuration)\</OutDir>
    <IntDir>$(Configuration)\</IntDir>
    <LinkIncremental>true</LinkIncremental>
    <LinkKeyFile>theCppCliLibraryName.snk</LinkKeyFile>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <OutDir>$(SolutionDir)$(Configuration)\</OutDir>
    <IntDir>$(Configuration)\</IntDir>
    <LinkIncremental>false</LinkIncremental>
    <LinkKeyFile>theCppCliLibraryName.snk</LinkKeyFile>
  </PropertyGroup>
  <ItemDeFinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <Optimization>disabled</Optimization>
      <AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <PreprocessorDeFinitions>WIN32;_DEBUG;%(PreprocessorDeFinitions)</PreprocessorDeFinitions>
      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
      <precompiledHeader>Use</precompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <DebuginformationFormat>ProgramDatabase</DebuginformationFormat>
    </ClCompile>
    <Link>
      <AdditionalDependencies>LicenseLib2015MDd.lib</AdditionalDependencies>
      <AdditionalLibraryDirectories>../../lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <GenerateDebuginformation>true</GenerateDebuginformation>
      <AssemblyDebug>true</AssemblyDebug>
      <RandomizedBaseAddress>false</RandomizedBaseAddress>
      <DataExecutionPrevention />
      <TargetMachine>MachineX86</TargetMachine>
      <Profile>true</Profile>
      <SubSystem>Windows</SubSystem>
    </Link>
  </ItemDeFinitionGroup>
  <ItemDeFinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <PreprocessorDeFinitions>WIN32;NDEBUG;%(PreprocessorDeFinitions)</PreprocessorDeFinitions>
      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
      <precompiledHeader>Use</precompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <DebuginformationFormat>ProgramDatabase</DebuginformationFormat>
    </ClCompile>
    <Link>
      <AdditionalDependencies>LicenseLib2015MD.lib</AdditionalDependencies>
      <AdditionalLibraryDirectories>../../lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <GenerateDebuginformation>false</GenerateDebuginformation>
      <RandomizedBaseAddress>false</RandomizedBaseAddress>
      <DataExecutionPrevention />
      <TargetMachine>MachineX86</TargetMachine>
      <SubSystem>Windows</SubSystem>
      <ShowProgress>LinkVerbose</ShowProgress>
    </Link>
  </ItemDeFinitionGroup>
  <ItemGroup>
    <Reference Include="log4net">
      <HintPath>..\3rdPartyLibraries\log4net-2.0.8\bin\net\4.5\release\log4net.dll</HintPath>
    </Reference>
    <Reference Include="System">
      <copyLocalSatelliteAssemblies>true</copyLocalSatelliteAssemblies>
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
    </Reference>
    <Reference Include="System.Data">
      <copyLocalSatelliteAssemblies>true</copyLocalSatelliteAssemblies>
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
    </Reference>
    <Reference Include="System.Drawing">
      <copyLocalSatelliteAssemblies>true</copyLocalSatelliteAssemblies>
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
    </Reference>
    <Reference Include="System.Windows.Forms">
      <copyLocalSatelliteAssemblies>true</copyLocalSatelliteAssemblies>
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
    </Reference>
    <Reference Include="System.Xml">
      <copyLocalSatelliteAssemblies>true</copyLocalSatelliteAssemblies>
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="AFile.cpp" />
    <ClCompile Include="BFile.cpp" />
    <ClCompile Include="Stdafx.cpp">
      <precompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</precompiledHeader>
      <precompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</precompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="AFile.h" />
    <ClInclude Include="BFile.h">
      <FileType>CppForm</FileType>
    </ClInclude>
    <ClInclude Include="resource.h" />
    <ClInclude Include="Stdafx.h" />
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="app.rc" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
  <ProjectExtensions>
    <VisualStudio>
      <UserProperties Spices_Obfuscationoptions="{Anonymizer=High}{AntiILDASM=CompleteImproved}{Members=Full}" />
    </VisualStudio>
  </ProjectExtensions>
</Project>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。