除非安装 visual studio,否则无法使用 C++/CLI DLL

Cannot use a C++/CLI DLL unless visual studio is installed

简介

我正在开发一个可以解释和使用 API 蓝图的工具。

我创建了一个新的控制台应用程序,添加了 SnowCrash.NET nuget package 并编写了这段代码:

    static void Main(string[] args)
    {
        snowcrashCLR.Blueprint blueprint;
        snowcrashCLR.Result result;

        var path = args.Length > 1 ? args[1] : @"c:\";

        snowcrashCLR.SnowCrashCLR.parse(path, out blueprint, out result);
        if (result != null)
        {
            var warnings = result.GetWarningsCs();
            foreach (var warning in warnings)
            {
                Console.WriteLine("{0}: {1}", warning.code, warning.message);
            }
        }
    }

问题

当我将代码(复制 bin 文件夹)部署到与我的开发环境不同的计算机时,我得到一个指向 SnowCrash.dll

的 FileNotFoundException

这是错误消息中的快照:

Could not load file or assembly 'snowcrashCLR.DLL' or one of its dependencies. The specified module could not be found.

详情:

[FileNotFoundException: Could not load file or assembly 'snowcrashCLR.DLL' or one of its dependencies. The specified module could not be found.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
   System.Reflection.Assembly.Load(String assemblyString) +28

到目前为止我尝试了什么

Load Image C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualC.STLCLR\v4.0_2.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualC.STLCLR.dll

MS Visual C++ 2005 Redist (x64)
MS Visual C++ 2008 Redist (x64) 9.0.30729.4148
MS Visual C++ 2008 Redist (x64) 9.0.30729.6161
MS Visual C++ 2008 Redist (x86) 9.0.30729.4148
MS Visual C++ 2008 Redist (x86) 9.0.30729.6161
MS Visual C++ 2010 x64 Redist - 10.0.40219
MS Visual C++ 2013 x64 Redist - 12.0.30501
MS Visual C++ 2013 x86 Redist - 12.0.30501

如果您有更好的知识或遇到类似问题,我们将不胜感激。

通过在互联网上进行大量挖掘,我发现 SnowCrash DLL 缺少 运行 所需的依赖项,即 Visual C++ 运行time 2012 x86。

由于它是一个混合的(托管 CLR + 本机)DLL,它需要 C++ MFC 库,它随 VC++ 运行time 一起提供。它必须是正确的版本才能 运行 正确。

this MSDN URL 的 运行time 安装到目标计算机上解决了我的问题。