简体   繁体   English

可以使用MSBuild + .csproj文件创建msi-installer吗?

[英]Can an msi-installer be created using MSBuild + .csproj-file?

For anyone using Visual Studio Express, who doesn't have the setup and deployment project template, can the .csproj file be used to easily create an msi installer? 对于使用Visual Studio Express但没有设置和部署项目模板的人,可以使用.csproj文件轻松创建msi安装程序吗? I've read (can't find the link now) that a csproj file can be used by MSBuild (It gets converted to an MSBuild project file by MSBuild) - so what is the need for InstallShield, WIX, or the setup and deployment project? 我读过(现在找不到链接)一个的csproj文件可以通过的MSBuild(它被转换到 MSBuild的MSBuild项目文件)使用-究竟什么是需要的InstallShield,维克斯,或安装和部署项目?

I realize this might be a simple question, but searching the web just turns up explanations why MSBuild is needed - and that's included in the framework itself. 我意识到这可能是一个简单的问题,但在网上搜索只是解释了为什么需要MSBuild - 而且它包含在框架本身中。

First a few clarifications: 首先澄清几点:

  • A .csproj is an MSBuild project file, as are most Visual Studio project files (including WiX projects). .csproj 一个MSBuild项目文件,大多数Visual Studio项目文件(包括WiX项目)也是如此。 A .sln file is not an MSBuild project file but MSBuild will convert it to one. .sln文件不是MSBuild项目文件,但MSBuild会将其转换为一个。
  • As of its most recent version, MSBuild is no longer part of the .NET Framework. 从最新版本开始,MSBuild不再是.NET Framework的一部分。 It is now in MS Build Tools, a separate, free product. 它现在是MS Build Tools,一个单独的免费产品。
  • Even with Visual Studio Express, you have full use of MSBuild. 即使使用Visual Studio Express,您也可以充分利用MSBuild。 Express does not allow non-Microsoft extensions to Visual Studio . Express不允许对Visual Studio进行非Microsoft 扩展 The WiX Toolset does provide both MSBuild targets/tasks files and a Visual Studio extension. WiX工具集确实提供了MSBuild目标/任务文件和Visual Studio扩展。 So, with Express, you don't have the WiX project template expander and editor. 因此,使用Express,您没有WiX项目模板扩展器和编辑器。

An alternative to Visual Studio is SharpDevelop. Visual Studio的另一种选择是SharpDevelop。 It provides its own WiX project templates. 它提供了自己的WiX项目模板。

You can also create a WiX project from scratch by hand, as explained in the documentation. 您也可以手动创建WiX项目,如文档中所述。

It is easy to create a simple MSI installer, with explicit lists of files. 使用明确的文件列表可以轻松创建简单的MSI安装程序。 You can also "harvest" .csproj outputs and some other Visual Studio project outputs, as well as directories, etc. 您还可以“收获”.csproj输出和一些其他Visual Studio项目输出,以及目录等。

Most any editor, including Visual Studio Express, will help you edit WiX project and source files as XML. 大多数编辑器(包括Visual Studio Express)都可以帮助您将WiX项目和源文件编辑为XML。 You might need to tell it where the relevant XML Schema files (.xsd) are to get content assistance. 您可能需要告诉它相关的XML Schema文件(.xsd)在哪里获得内容帮助。 The zipped binary distribution of WiX might be simplest to use in such scenarios. 在这种情况下,WiX的压缩二进制分发可能最简单。

Windows Installer is very complex. Windows Installer非常复杂。 The WiX Toolset allows full access to that complexity while attempting to kept it as simple as possible. WiX工具集允许完全访问该复杂性,同时尽量使其保持简单。 Using WiX means learning at least some of Windows Installer. 使用WiX意味着至少学习一些Windows Installer。

Ultimately, no installer tool can look at your programming project and decide for you which files you want to ship and where to put them. 最终,没有任何安装程序工具可以查看您的编程项目,并决定您要发送哪些文件以及放置它们的位置。 So, no, you can't design and build an MSI simply by referencing a .csproj. 所以,不,你不能简单地通过引用.csproj来设计和构建MSI。

I think WiX would be the best option here. 我认为WiX将是最好的选择。 Building installer using Wix is basically a simple call to candle.exe and then light.exe so it can be automated in custom MSBuild target inside of your .csproj without any problem. 使用Wix构建安装程序基本上是对candle.exelight.exe的简单调用,因此它可以在.csproj内的自定义MSBuild目标中自动执行,没有任何问题。

It would require however to set the environment that .wixproj projects usually do. 但是,需要设置.wixproj项目通常所做的环境。 For example, you would need to locate WixSDK to use candle/light binaries and pass $(OutputPath) property to candle.exe so that output files could be used in your .wxs . 例如,您需要找到WixSDK以使用蜡烛/灯光二进制文件并将$(OutputPath)属性传递给candle.exe,以便可以在.wxs中使用输出文件。

After all, there would be a target like this that starts the installer build: 毕竟,会有一个这样的目标启动安装程序构建:

<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
    <Exec Command="$(candleExecutable) product.wxs" />
    <Exec Command="$(lightExecutable) product.wixobj" />
</Target>

You could also add a condition to this target so that it's called on a specific configuration only. 您还可以向此目标添加条件,以便仅在特定配置上调用它。

No, I don't believe there's any way to do that with Express. 不,我不相信Express有任何办法可以做到这一点。 It's not a built-in feature, and you can't use add-ins with Express. 它不是内置功能,您不能使用Express加载项。

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

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