gpt4 book ai didi

c++ - 在 C++/CLR 项目中引用 NuGet 包时编译器警告 C4691

转载 作者:行者123 更新时间:2023-12-02 10:39:25 25 4
gpt4 key购买 nike

我在 Visual Studio 2017 中有以下情况:

使用/clr(公共(public)语言运行时支持开关)编译的 C++ 项目依赖于 Microsoft.Practices.Unity,因为我们在其中使用了 IUnityContainer。但是,在引用的 cpp 文件中会出现几个警告:

using namespace Microsoft::Practices::Unity;

构建后的警告:
warning C4691: 'System::Object': type referenced was expected in unreferenced assembly 'System.Runtime', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
warning C4691: 'System::IDisposable': type referenced was expected in unreferenced assembly 'System.Runtime', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::IUnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
warning C4691: 'System::Collections::Generic::IEnumerable': type referenced was expected in unreferenced assembly 'System.Runtime', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::IUnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
warning C4691: 'System::ParamArrayAttribute': type referenced was expected in unreferenced assembly 'System.Runtime', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::IUnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
warning C4691: 'System::Type': type referenced was expected in unreferenced assembly 'System.Runtime', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::IUnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
warning C4691: 'System::EventHandler': type referenced was expected in unreferenced assembly 'System.Runtime', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
warning C4691: 'System::Collections::Generic::IDictionary': type referenced was expected in unreferenced assembly 'System.Runtime', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
warning C4691: 'System::Collections::Generic::List': type referenced was expected in unreferenced assembly 'System.Collections', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.
warning C4691: 'System::Action': type referenced was expected in unreferenced assembly 'System.Runtime', type defined in current translation unit used instead
note: This diagnostic occurred while importing type 'Microsoft::Practices::Unity::UnityContainer ' from assembly 'Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f'.

我已经在几个地方找到了以下主题,它们似乎以某种方式解决了这个问题,但不幸的是,没有任何对我的情况有帮助的修复。
  • https://github.com/aspnet/Logging/issues/734
  • https://github.com/dotnet/sdk/issues/1781
  • https://developercommunity.visualstudio.com/content/problem/158463/c4691-warnings-with-ccli-nuget.html

  • 除了通过#pragma 将其停用之外,是否有人已经找到了避免此警告的解决方案?

    修改 :
    通过在 Visual Studio 2017 中创建一个新的 CLR 控制台应用程序项目,添加对 Microsoft.Practices.Unity.dll(版本 4.0.1,来自 NuGet 包的 net45 文件夹)的引用和以下代码段,可以简单地重现该问题:
    #include "stdafx.h"

    using namespace System;


    int main(array<System::String ^> ^args)
    {
    Microsoft::Practices::Unity::IUnityContainer^ unityContainer = gcnew Microsoft::Practices::Unity::UnityContainer();
    return 0;
    }

    最佳答案

    我通过更新 Unity 的 NuGet 包解决了这个问题。旧的 Unity 包仅包含 4.5 版以下的 dll,而在项目中设置了 4.6.2 版。

    通过将统一包更新到最新版本(当前为 5.8.2,与 .net 框架最高 4.7 兼容),警告完全消失了!

    关于c++ - 在 C++/CLR 项目中引用 NuGet 包时编译器警告 C4691,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50949789/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com