我的Visual Studio 2019 WPF应用程序应将dll设置为输出时应将其设置为exe [英] My Visual Studio 2019 WPF app is setting a dll as the output when it should be an exe

查看:418
本文介绍了我的Visual Studio 2019 WPF应用程序应将dll设置为输出时应将其设置为exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试制作可部署的程序.创建好运行的WPF XAML小应用程序(即我可以在bin文件夹中运行可执行文件)后,我尝试将其包装在安装程序中.

This is my first time trying to make a deployable program. After creating a nice little WPF XAML app that runs (i.e. I can run the executable in the bin folder), I am trying to wrap it in a setup program.

针对WiX和"Microsoft Visual Studio安装程序项目"在线遵循多个说明之后.两者都生成安装程序包,但是当我使用主要输出"时,它们仅针对WPF XAML输出中的dll文件.看来这是由于WPF项目的建立而引起的.

After following multiple directions online for both WiX and "Microsoft Visual Studio Installer Projects". Both make installer packages, but they are only targeting the dll file from the WPF XAML output when I as for the "Primary Output". It seems this is stemming from the build of the WPF project.

如何调整构建过程的主要输出,使其包含在安装程序中?

How do I adjust the primary output of the build process so it is included in the setup program?

将dll指定为输出文件的构建输出的屏幕截图:

Screenshot of build output specifying the dll as the output file:

添加更多详细信息:

这可能是一个wpf(.net core)应用程序,而不是一个wpf(.net framework).参见Elton屏幕截图中的Output窗口,我们可以找到输出是xx.dll而不是xx.exe.

This could be one wpf(.net core) application instead of one wpf(.net framework). See the Output window in Elton's screenshot we can find the output is xx.dll instead of xx.exe.

如果我们在此解决方案中创建一个Installer项目,请右键单击Installer项目=> Add => Project Output => Primary输出以将WPF的输出包含在installer项目中,只有xx.dll被视为wpf的输出,但不是xx.exe.

If we create a Installer project in this solution, right-click the Installer project=>Add=>Project Output=>Primary output to contain the WPF's output in installer project, only the xx.dll is considered as wpf's output, but not xx.exe.

因此,在VS中构建Installer项目后,双击setup.exe(安装程序项目的输出),则wpf.exe的安装不正确.

So after building the Installer project in VS, double-click the setup.exe(installer project's output), the wpf.exe is not well installed.

推荐答案

我的Visual Studio 2019 WPF应用程序在将dll设置为输出时 应该是一个exe文件.

My Visual Studio 2019 WPF app is setting a dll as the output when it should be an exe.

我确定您使用的是WPF(.net core)项目,因为昨天我碰巧在机器上重现了同样的情况.至于问题的原因,如果您对此感兴趣,可以从

I'm sure you're using a WPF(.net core) project cause yesterday I happened to reproduce same situation in my machine. As for the cause of the issue, if you're interested in it, you may get some help from this issue. For .net core 2.2 and earlier, if we build a console(.net core) project, we'll get a xx.dll as output by default(Use dotnet xx.dll to run that).

但是对于.net core 3.0,我发现这种情况发生了变化.现在,如果我们构建一个Console(.net核心)或WPF(.net核心),除了xx.dll之外,我们现在还将获得一个xx.exe.然后,我检查了安装程序项目的更新日期以及WPF( .net核心),Installer项目的最新更新比WPF(.net核心)的发布要早得多,我想这可能是原因吗?我不确定安装程序项目如何识别一个WPF项目的输出,但是我建议您可以在 DC论坛,如果获得足够的选票,团队将考虑解决.

But for .net core 3.0, I found this situation changes. Now if we build a Console(.net core) or WPF(.net core), apart from the xx.dll, we'll also get an xx.exe now. And I checked the Updated date of Installer Project and the Release date of WPF(.net core), the latest update of the Installer project is much earlier than the release of WPF(.net core), I guess maybe this is the cause? I'm not certainly sure how Installer Project recognize the output of one WPF project, but I suggest you can post this issue in DC forum , if it gets enough votes, the team will consider a fix.

以下是我的解决方法,可能会有所帮助:

1.使用Add=>File代替Add=>Primary Output:

以发布模式构建WPF项目,导航到输出路径并复制该路径.然后右键单击Installer project => Add => Files以输入该路径.选择输出文件夹中的所有文件,然后单击打开:

Build the WPF project in release mode, navigate to the output path and copy that path. Then right-click Installer project=>Add=>Files to enter that path. Choose all files in output folder and click open:

右键单击程序集文件,然后选择在编辑器中查找:

Right-click the assembly file and choose Find in Editor:

右键单击xx.exe =>创建快捷方式.然后将快捷方式移动到User's Desktop folder并将AlwaysCreate属性设置为true.

Right-click the xx.exe=>Create a shortcut. Then move the shortcut to User's Desktop folder and set the AlwaysCreate property to be true.

然后,构建安装程序项目并将该xx.msi或setup.exe安装到我的计算机中,我将在桌面上找到一个快捷方式,双击它将运行wpf(core)应用程序.

After that, build the installer project and install that xx.msi or setup.exe in my machine, I'll get a shortcut in desktop, double-click it will run the wpf(core) application.

2.请参见这个问题.

2.See this blog, we can use command like dotnet publish -r xxx -p:PublishSingleFile=true to get a single-file executable which is self-extracting and contains all dependencies (including native) that are required to run your app. In this situation, you don't need a Installer project to deploy your project. The single executable is enough. Hint from Lex Li in this issue.

希望它会有所帮助:-)

Hope it helps :-)

这篇关于我的Visual Studio 2019 WPF应用程序应将dll设置为输出时应将其设置为exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆