visual studio自定义必备组件

目的

我们希望在visual studio生成安装包时候有些必备组件如.net framework可以打包进安装包,这样可以避免在安装exe应用程序的时候需提前安装这些组件,我们可以在解决方案管理器-右键项目名称或者安装项目setup,选择属性-prerequisites-选择需要预安装的组件。
visual studio自定义必备组件_第1张图片
但是visual studio自带的可选组件只有一些.net framework组件或SQL Server组件,有时候我们希望将一些特定的驱动或者环境也打包进安装包中,这时候就需要我们添加这些驱动或者环境到visual studio的系统必备组件可选列表中。

方法

1.找到系统中存放这些必备组件的位置,我的是C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages,里面有现在visual studio必备组件对应的文件夹,这个位置跟你安装时候路径选择有关,如果不是这个路径的话可以看一下C:\Program Files (x86)\Microsoft\SDKs\Windows\v7.0A\Bootstrapper\Packages
或者C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\Bootstrapper\Packages
或者C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages
或者C:\Program Files\Microsoft SDKs\Windows\v10.0A\Bootstrapper\Packages

2.在这个路径下创建一个你要添加的组件对应的文件夹,文件夹的名自定义,可以为你要添加的组件名,如UpdateConsentDialog
visual studio自定义必备组件_第2张图片

3.在创建的组件目录下将你要添加的组件copy如CH341SER.EXE进来

4.在创建的组件目录下创建一个product.xml文件,里面填入

<Product
  xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
  ProductCode="Microsoft.Sample.EULA">
  <!-- Defines the list of files to be copied on build. -->
  <PackageFiles CopyAllPackageFiles="false">
    <PackageFile Name="CH341SER.EXE"/>
  </PackageFiles>

  <!-- Defines how to run the Setup package.-->
  <Commands >
    <Command PackageFile = "CH341SER.EXE" Arguments=''>
      <ExitCodes>
        <ExitCode Value="0" Result="Success" />
        <ExitCode Value="-1" Result="Fail" String="AU_Unaccepted" />
        <DefaultExitCode Result="Fail"
          FormatMessageFromSystem="true" String="GeneralFailure" />
      </ExitCodes>
    </Command>
  </Commands>

</Product>

注意这里的PackageFile Name与Command PackageFile都要填你之前copy进文件夹的组件,也就是你需要预安装的组件,这里是CH341SER.EXE

5.在UpdateConsentDialog路径下创建一个文件夹名为en
在这里插入图片描述

6.在en文件夹下创建一个eula.rtf文件,里面填入


MICROSOFT SOFTWARE SUPPLEMENTAL LICENSE TERMS
MICROSOFT .NET FRAMEWORK 4 FOR MICROSOFT WINDOWS OPERATING SYSTEM 
MICROSOFT .NET FRAMEWORK 4 CLIENT PROFILE FOR MICROSOFT WINDOWS OPERATING SYSTEM 
AND ASSOCIATED LANGUAGE PACKS
Microsoft Corporation (or based on where you live, one of its affiliates) licenses this supplement to you.  If you are licensed to use Microsoft Windows operating system software (for which this supplement is applicable) (the “software”), you may use this supplement.  You may not use it if you do not have a license for the software.  You may use a copy of this supplement with each validly licensed copy of the software.
The following license terms describe additional use terms for this supplement.  These terms and the license terms for the software apply to your use of the supplement.  If there is a conflict, these supplemental license terms apply.
By using this supplement, you accept these terms.  If you do not accept them, do not use this supplement.
If you comply with these license terms, you have the rights below.
1.	SUPPORT SERVICES FOR SUPPLEMENT.  Microsoft provides support services for this software as described at www.support.microsoft.com/common/international.aspx.
2.	MICROSOFT .NET FRAMEWORK BENCHMARK TESTING. The software includes one or more components of the .NET Framework (.NET Components).  You may conduct internal benchmark testing of those components. You may disclose the results of any benchmark test of those components, provided that you comply with the conditions set forth at http://go.microsoft.com/fwlink/?LinkID=66406.
Notwithstanding any other agreement you may have with Microsoft, if you disclose such benchmark test results, Microsoft shall have the right to disclose the results of benchmark tests it conducts of your products that compete with the applicable .NET Component, provided it complies with the same conditions set forth at http://go.microsoft.com/fwlink/?LinkID=66406.

7.在en文件夹中创建一个package.xml文件,里面填入

<Package
  xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"
  Name="DisplayName"
  Culture="Culture"
  LicenseAgreement="eula.rtf">
  <PackageFiles>
    <PackageFile Name="eula.rtf"/>
  </PackageFiles>

  <!-- Defines a localizable string table for error messages. -->
  <Strings>
    <String Name="DisplayName">Update Consent Dialog</String>
    <String Name="Culture">en</String>
    <String Name="AU_Unaccepted">The automatic update agreement is not accepted.</String>
    <String Name="GeneralFailure">A failure occurred attempting to launch the setup.</String>
  </Strings>
</Package>

注意这里的DiaplayName后面填的名称就是将会出现在visual studio必备组件列表中的名称,我这里填的是Update Consent Dialog

8.也可以在UpdateConsentDialog文件夹中添加一些文件夹如de表示德语,fr表示法语,里面的文件基本相同,但是换成对应语法的。当然这些不是一定要的,看个人意愿和需求

9.这些添加完毕后,重新打开visual studio的必备组件,就能发现多了一个名为Update Consent Dialog的组件
visual studio自定义必备组件_第3张图片

你可能感兴趣的:(C#)