C# 部署无需安装即可运行的 Visual Studio 应用程序的最佳方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16946173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to deploy Visual Studio application that can run without installing
提问by Wilson
I wrote a fairly simple application with C#/.NET and can't figure out a good way to publish it. It's a sort of a "tool" that users would only run once, or run every few months. Because of this, I'm hoping that there is a way I could deploy it where it wouldn't need installing to run (it could just be run by double clicking an EXE file straight after downloading).
我用 C#/.NET 编写了一个相当简单的应用程序,但找不到发布它的好方法。这是一种用户只会运行一次或每隔几个月运行一次的“工具”。因此,我希望有一种方法可以将它部署到不需要安装即可运行的地方(它可以在下载后直接双击 EXE 文件来运行)。
However, it still needs (somehow) to include the correct version of .NET, libraries, etc. so it will run correctly. I know this is included when using ClickOnce, but that still installs the application onto the user's computer.
但是,它仍然需要(以某种方式)包含正确版本的 .NET、库等,以便正确运行。我知道这在使用 ClickOnce 时包含在内,但仍会将应用程序安装到用户的计算机上。
Is there a way this can be done?
有没有办法做到这一点?
EDIT - \bin\Debug
编辑 - \bin\Debug
myAppName.application
myAppName.exe
myAppName.exe.config
myAppName.exe.manifest
myAppName.pdb
myAppName.vshost.application
myAppName.vshost.exe
myAppName.vshost.exe.config
myAppName.vshost.exe.manifest
extraLibrary.dll
as well as two folders
以及两个文件夹
app.publish
Resources
采纳答案by Peter Mortensen
It is possible and is deceptively easy:
这是可能的,而且看似简单:
- "Publish" the application (to, say, some folder on drive C), either from menu Buildor from the project's properties → Publish. This will create an installer for a ClickOnceapplication.
- But instead of using the produced installer, find the produced files (the EXE file and the .config, .manifest, and .applicationfiles, along with any DLL files, etc.) - they are all in the same folder and typically in the
bin\Debugfolder below the project file (.csproj). - Zip that folder (leave out any *.vhost.*files and the
app.publishfolder (they are not needed), and the .pdb files unless you foresee debugging directly on your user's system (for example, by remote control)), and provide it to the users.
- 从菜单Build或从项目的属性 → Publish 中“发布”应用程序(例如,到驱动器 C 上的某个文件夹)。这将为ClickOnce应用程序创建一个安装程序。
- 但不是使用生成的安装程序,而是找到生成的文件(EXE 文件和.config、.manifest和.application文件,以及任何 DLL 文件等)——它们都在同一个文件夹中,通常在
bin\Debug项目文件 ( .csproj)下的文件夹。 - 压缩该文件夹(省略任何*.vhost.*文件和
app.publish文件夹(不需要它们)以及 .pdb 文件,除非您预见直接在用户系统上进行调试(例如,通过远程控制)),并提供它给用户。
An added advantage is that, as a ClickOnce application, it does not require administrative privileges to run (if your application follows the normal guidelines for which folders to use for application data, etc.).
另一个优点是,作为 ClickOnce 应用程序,它不需要管理权限即可运行(如果您的应用程序遵循用于应用程序数据的文件夹等的正常准则)。
As for .NET, you can check for the minimum required version of .NET being installed (or at all) in the application (most users will already have it installed) and present a dialog with a link to the download page on the Microsoft website (or point to one of your pages that could redirect to the Microsoft page - this makes it more robust if the Microsoft URL change). As it is a small utility, you could target .NET 2.0 to reduce the probability of a user to have to install .NET.
至于 .NET,您可以检查应用程序中安装(或根本安装)所需的最低 .NET 版本(大多数用户已经安装了),并显示一个对话框,其中包含指向 Microsoft 网站上下载页面的链接(或指向可以重定向到 Microsoft 页面的页面之一 - 如果 Microsoft URL 更改,这会使其更加强大)。由于它是一个小型实用程序,您可以针对 .NET 2.0 来降低用户必须安装 .NET 的可能性。
It works. We use this method during development and test to avoid having to constantly uninstall and install the application and still being quite close to how the final application will run.
有用。我们在开发和测试期间使用这种方法,以避免必须不断卸载和安装应用程序,并且仍然非常接近最终应用程序的运行方式。
回答by abe312
First you need to publish the file by:
首先,您需要通过以下方式发布文件:
BUILD -> PUBLISH or by right clicking project on Solution Explorer -> properties -> publish or select project in Solution Explorer and press Alt+ EnterNOTE: if you are using Visual Studio 2013then in properties you have to go to BUILD and then you have to disable define DEBUG constant and define TRACE constant and you are ready to go.

Save your file to a particular folder. Find the produced files (the EXE file and the .config, .manifest, and .application files, along with any DLL files, etc.) - they are all in the same folder and typically in the
bin\Debugfolder below the project file (.csproj). In Visual Studio they are in the Application Files folder and inside that you just need the .exe and dll files. (You have to delete ClickOnce and other files and then make this folder a zip file and distribute it.)
BUILD -> PUBLISH 或通过右键单击解决方案资源管理器上的项目 -> 属性 -> 在解决方案资源管理器中发布或选择项目并按Alt+Enter注意:如果您使用的是Visual Studio 2013,则在属性中您必须转到 BUILD,然后您必须禁用定义 DEBUG 常量并定义 TRACE 常量,您就可以开始了。

将文件保存到特定文件夹。找到生成的文件(EXE 文件和 .config、.manifest 和 .application 文件,以及任何 DLL 文件等)——它们都在同一个文件夹中,通常在
bin\Debug项目文件 (.csproj) 下面的文件夹中)。在 Visual Studio 中,它们位于 Application Files 文件夹中,在其中您只需要 .exe 和 dll 文件。(您必须删除 ClickOnce 和其他文件,然后将此文件夹设为 zip 文件并分发。)
NOTE: The ClickOnce application does install the project to system, but it has one advantage. You DO NOT require administrative privileges here to run (if your application follows the normal guidelines for which folders to use for application data, etc.).
注意: ClickOnce 应用程序确实将项目安装到系统,但它有一个优点。您在此处不需要管理权限即可运行(如果您的应用程序遵循用于应用程序数据的文件夹等的正常准则)。

