简体   繁体   English

Visual Studio 安装程序项目打包 DotNetCore 而不是 Framework

[英]Visual Studio Installer Project packaging DotNetCore instead of Framework

I've been going circles on this one for over a day now.我已经在这个问题上转了一天多了。 I have a WPF project that is making use of sqlite-net-pcl .我有一个使用sqlite-net-pcl的 WPF 项目。

I'm ready to package this project up into an MSI for distribution (x64).我已准备好将此项目打包到 MSI 中以进行分发 (x64)。 The first hitch was that I need to directly add the nuget for the dependency ( SQLitePCLRaw.bundle_green ).第一个障碍是我需要直接为依赖项( SQLitePCLRaw.bundle_green )添加SQLitePCLRaw.bundle_green I've come across this before when a nuget package contains content files that need to find their way into the final release.我之前遇到过这种情况,当 nuget 包包含需要进入最终版本的内容文件时。 Smooth sailing.一帆风顺。

At this point, the bin/x64/release is good and runs fine.在这一点上, bin/x64/release是好的并且运行良好。 However, when I build an installer and run the installed version I get the following exception:但是,当我构建安装程序并运行已安装的版本时,出现以下异常:

System.BadImageFormatException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. System.BadImageFormatException:无法加载文件或程序集“System.Runtime.CompilerServices.Unsafe,Version=4.0.4.1,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。 Reference assemblies should not be loaded for execution.不应为执行加载引用程序集。 They can only be loaded in the Reflection-only loader context.它们只能在仅反射加载器上下文中加载。 (Exception from HRESULT: 0x80131058) ---> System.BadImageFormatException: Cannot load a reference assembly for execution. (来自 HRESULT 的异常:0x80131058)---> System.BadImageFormatException:无法加载要执行的引用程序集。

Doing a file compare between my release folder and the application install folder I find the following:在我的发布文件夹和应用程序安装文件夹之间进行文件比较,我发现以下内容:

    Binary Difference: System.Buffers.dll
    Binary Difference: System.Numerics.Vectors.dll
    Binary Difference: System.Runtime.CompilerServices.Unsafe.dll
    Installer Only: netstandard.dll
    Installer Only: System.Diagnostics.Tracing.dll
    Installer Only: System.IO.Compression.dll
    Installer Only: System.IO.Compression.FileSystem.dll
    Installer Only: System.Net.Http.dll

After inspecting further and digging in to the DLLs, I find if I overwrite System.Runtime.CompilerServices.Unsafe.dll with the binary from my release folder everything works.在进一步检查并深入研究 DLL 后,我发现如果我用我的发布文件夹中的二进制文件覆盖System.Runtime.CompilerServices.Unsafe.dll一切正常。

Digging in even further and inspecting the installer version of CompilerServices.Unsafe I realize that the installer is grabbing the dotnet core version of the DLL.进一步深入研究并检查CompilerServices.Unsafe的安装程序版本,我意识到安装程序正在获取 DLL 的 dotnet 核心版本。

I've isolated this down to a single console app with a fresh installer project and only adding the content and output to the installer.我已将其隔离为具有全新安装程序项目的单个控制台应用程序,并且仅将contentoutput添加到安装程序。

Why is the installer insisting that the dependency is a dotnet core version?为什么安装程序坚持认为依赖项是 dotnet 核心版本?

I'd like to find a real solution, but in the meantime I found some confirmation and a dirty workaround in this thread: https://developercommunity.visualstudio.com/content/problem/810090/visual-studio-installer-projects-extensions-incorr.html我想找到一个真正的解决方案,但与此同时我在这个线程中找到了一些确认和一个肮脏的解决方法: https : //developercommunity.visualstudio.com/content/problem/810090/visual-studio-installer-projects- extensions-incorr.html

Workaround option 1: In addition to adding the “Primary Output” of the project containing the package reference also add “Locally-Copied Items” for that project.解决方法选项 1:除了添加包含包引用的项目的“主要输出”之外,还为该项目添加“本地复制的项目”。 This will result in the lib version of the assembly overwriting the ref version, giving you the behavior you want.这将导致程序集的 lib 版本覆盖 ref 版本,为您提供所需的行为。 However, you'll also get a warning about the duplicate file being added, since as I said the lib version will be overwriting the ref version.但是,您还会收到有关添加重复文件的警告,因为正如我所说,lib 版本将覆盖 ref 版本。 This also could bring in additional files like xml doc files that should have no impact at runtime but may increase the size of the installer.这也可能会引入额外的文件,如 xml doc 文件,这些文件在运行时应该没有影响,但可能会增加安装程序的大小。 These can also be individually excluded from the setup project.这些也可以从安装项目中单独排除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM