c++ /CLI库将.netcore作为VS 2017 c++应用程序的依赖项



我正在尝试从c++应用程序调用。net core函数。

为此,我有一个c++/CLI库,它将。net core库作为依赖项,然后从该库调用。net core函数。我把这个c++/CLI库作为一个c++应用程序的依赖项,然后运行这个c++应用程序。

c++/CLI library ->TestCPPCLI

。Netcore库->TestNetcoreDll

VS 2017 c++应用程序->Testcpp

当我尝试运行c++应用程序时,我得到错误Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'TestNetcoreDll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

在编译TestCPPCLI时,我得到这个链接器警告1>LINK : warning LNK4199: /DELAYLOAD:TestNetcoreDll.dll ignored; no imports found from CVMQClient.dll

在VS2017 c++应用程序中,我们可以依赖于针对。net core的c++/CLI库吗?

如何在vcxproj的c++/CLI应用程序中包含。net core库?

<Import Project="$(VCTargetsPath)Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>NetCore</CLRSupport>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>NetCore</CLRSupport>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<ItemGroup>
<Reference Include="TestNetcoreDll">
<HintPath>......Buildx64ReleaseTestNetcoreDll.dll</HintPath>
</Reference>      
</ItemGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MkTypLibCompatible>true</MkTypLibCompatible>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TargetEnvironment>Win32</TargetEnvironment>
<TypeLibraryName>$(OutDir)$(ProjectName).tlb</TypeLibraryName>
</Midl>
<ClCompile>
<ForcedUsingFiles>TestNetcoreDll.dll</ForcedUsingFiles>
</ClCompile>

<Link>
<DelayLoadDLLs>TestNetcoreDll.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>

vcxproj中,我在AdditionalLibraryDirectoriesAdditionalIncludeDirectories中也包含了库和头文件位置

不,你不能链接dll,你需要添加它作为引用。

<ItemGroup>
<Reference Include="TestNetcoreDll">
<HintPath>TestNetcoreDll.dll</HintPath>
</Reference>
</ItemGroup>
<!--ClCompile>
<ForcedUsingFiles>TestNetcoreDll.dll</ForcedUsingFiles>
</ClCompile>
<Link>
<DelayLoadDLLs>TestNetcoreDll.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link-->

最新更新