visual studio installer命令行创建离线安装包,向离线安装包中添加msvc2015和msvc2017相关组件的命令是
时间: 2024-10-08 16:11:31 浏览: 33
在Visual Studio Installer (MSI) 中,创建包含特定组件(如 Visual C++ 2015 和 2017)的离线安装包通常涉及使用`vstsdk`工具集。首先,你需要获取`vcredist_x64.exe`和`vcredist_x86.exe`文件,并将它们添加到源目录。然后,你可以通过以下步骤操作:
1. 打开命令提示符并导航至`vstsdk`安装目录,例如`C:\Program Files (x86)\Microsoft SDKs\Windows\v14.0A\Bootstrapper\Packages`。
2. 创建一个新的`WiX`项目,这将作为基础模板来生成安装包。运行如下命令:
```
msbuild /t:CreateNewProject /p:Name=MySetup.wixproj
```
3. 修改`MySetup.wixproj`项目的XML配置,确保它引用了需要的.NET Framework和Visual C++ redistributables。你可以找到类似这样的条目:
```xml
<Product Id="*" Name="My Product" Version="1.0.0.0" Language="1033" Manufacturer="Your Company">
<Package Id="*" Keywords="Installer" Description="My Product Setup" Comments="" InstallerVersion="100" Compressed="yes" InstallScope="perMachine" />
<Media Id="1" Cabinet="product.cab" EmbedCab="yes" />
<Feature Id="Full" Level="1">
<ComponentRef Id="NetFx45Redist" />
<ComponentRef Id="VC_redist" />
</Feature>
</Product>
```
其中`VC_redist`代表你的C++版本组件。
4. 添加`vcredist_x64.exe`和`vcredist_x86.exe`到安装包。在`.wxs`文件里,添加`CustomAction`元素来安装这些组件,例如:
```xml
<Binary Id="vcredist_x64" SourceFile="[VSInstallDir]\[vc_redist].exe" />
<Binary Id="vcredist_x86" SourceFile="[VSInstallDir]\[vc_redist_x86].exe" />
<CustomAction Id="InstallVcRedists" BinaryKey="vcredist_x64" DllEntry="RunDLL32"
Execute="deferred" Return="check" Impersonate="no" />
<CustomAction Id="InstallVcRedists_x86" BinaryKey="vcredist_x86" DllEntry="RunDLL32"
Execute="deferred" Return="check" Impersonate="no" />
<InstallExecuteSequence>
<!-- Add your VC Redistributable installation steps here -->
<Custom Action='InstallVcRedists' After='CostFinalize' />
<Custom Action='InstallVcRedists_x86' After='InstallVcRedists' If='VersionNT64 = false' />
</InstallExecuteSequence>
```
5. 使用` candle`和`light`命令构建离线安装包:
```
candle MySetup.wxs
light -out:MySetup.msi MySetup.wixobj
```
请注意,实际路径和组件名称(如`[vc_redist]`、`[vc_redist_x86]`等)需要替换为你下载的实际组件文件名和Visual Studio安装路径。
阅读全文