c# - 依赖于 Visual C++ 2013 运行时的 NuGet 包

标签 c# c++ visual-c++ nuget nuget-package

我已经从 .NET4.0 DLL 创建了一个 NuGet 包,其中包含混合(托管和 native )代码。

native 代码打包在 .NET4.0 DLL 中,但依赖于 Visual C++ 2013 Redistributable

我正在尝试集思广益,用 NuGet 包打包 redist 和/或警告用户他们需要它,但我一无所获。

有人有什么想法吗?

最佳答案

实际上我自己解决了这个问题。虽然我找不到将 VCpp 运行时作为 NuGet 包的依赖项包含在内的解决方案,但我确实找到了一个警告用户需要 Visual C++ 2013 运行时的解决方案。

我在启动需要 VC++ 运行时的组件/库时静态运行此代码一次:

    private static void AssertVcppDependencies()
    {
        var system32Path = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86);
        var system64Path = Environment.GetFolderPath(Environment.SpecialFolder.System);

        string platform = Environment.Is64BitProcess ? "x64 and x86" : "x86";
        bool success = File.Exists(Path.Combine(system32Path, MSVCP120DllName));

        if (Environment.Is64BitProcess)
        {
            success &= File.Exists(Path.Combine(system64Path, MSVCP120DllName));
        }            

        if (!success)
        {
            throw new InvalidOperationException("This Application Requires the Visual C++ 2013 " + platform + 
                " Runtime to be installed on this computer. Please download and install it from https://www.microsoft.com/en-GB/download/details.aspx?id=40784");
        }
    }

这应该提醒所有正在使用您的 NuGet 包的开发人员他们需要安装运行时。

关于c# - 依赖于 Visual C++ 2013 运行时的 NuGet 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33779063/

相关文章:

c# - 如何从 RestSharp 获取响应数据以供用户下载?

C++ 类 : Object that creates Thread + pointer to the function = Access violation

c++ - sqlite 数据库保持锁定/不可访问

c++ - 动态链接库 : export as a C/C++ function?

visual-c++ - 如何等待 ShellExecute 运行?

c# - 集成测试 ASP.NET Core Web API 和 EF Core 时重新配置依赖项

c# - mvc重复用户验证错误

c# - 如何在 fake it easy 中正确断言 MustHaveHappend(object)

c++ - 为什么没有 std::on_exit?

visual-c++ - 重新定义默认参数错误而不重新定义