简体   繁体   English

如何安装.NET Framework 4.0作为安装的一部分?

[英]How to install .NET framework 4.0 as part of installation?

I created bootstrapper,it works but it does not install NET Framework 4.0. 我创建了bootstrapper,它可以工作,但它不安装.NET Framework 4.0。 After the installation completed my application does not start because no NET Framework 4.0. 安装完成后,我的应用程序无法启动,因为没有.NET Framework 4.0。 Why it does not install NETF 4.0? 为什么不安装NETF 4.0?

<ItemGroup>
    <BootstrapperFile Include="Microsoft.Windows.Installer.4.5">
      <ProductName>Windows Installer 4.5</ProductName>
    </BootstrapperFile>
       <BootstrapperPackage Include=".NETFramework,Version=v4.0">
            <Visible>True</Visible>
            <ProductName>.NET Framework 4.0</ProductName>
            <Install>True</Install>
        <Visible>True</Visible>
      </BootstrapperPackage>
  </ItemGroup>
  <Import Project="$(WixTargetsPath)" />
  <Target Name="AfterBuild">
    <GenerateBootstrapper ApplicationFile="DOGInstaller.msi" 
    ApplicationName="DOG" 
    BootstrapperItems="@(BootstrapperFile)" 
    CopyComponents="True" 
    ComponentsLocation="HomeSite"
    OutputPath="$(OutputPath)\en-us\"
    Path="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper" 
    Culture="en" />
  </Target>

In the wixproj file, add the following structure. 在wixproj文件中,添加以下结构。 Note that the <WixTargetsPath> tags must reside in the the first <PropertyGroup> node, along with the rest of what's usually there. 请注意, <WixTargetsPath>标记必须位于第一个<PropertyGroup>节点中,以及通常存在的其余部分。

<Project>
  <PropertyGroup> <!-- This must be the first PropertyGroup node. -->
    ...
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
  </PropertyGroup>
  ...
  <ItemGroup>
    <BootstrapperFile Include="Microsoft.Windows.Installer.3.1">
      <ProductName>Windows Installer 3.1</ProductName>
    </BootstrapperFile>
    <BootstrapperFile Include=".NETFramework,Version=v4.0">
      <ProductName>Microsoft .NET Framework 4.0 (x86 and x64)</ProductName>
    </BootstrapperFile>
  </ItemGroup>
  <PropertyGroup>
    <BootstrapperPath>$(ProgramFiles)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\</BootstrapperPath>
  </PropertyGroup>
  <Target Name="AfterBuild">
    <GenerateBootstrapper
      ApplicationFile="$(TargetFileName)"
      ApplicationName="$(OutputName)"
      BootstrapperItems="@(BootstrapperFile)"
      ComponentsLocation="Relative"
      CopyComponents="True"
      OutputPath="$(OutputPath)"
      Path="$(BootstrapperPath)" />
  </Target>
</Product>

All items in the item group need to have the same name, "BootstrapperFile" - currently you will have two item groups, so the .Net Framework will not be included in the bootstrapper (as it's in a different item group called "BootstrapperPackage". 项目组中的所有项目都需要具有相同的名称“BootstrapperFile” - 目前您将有两个项目组,因此.Net Framework不会包含在引导程序中(因为它位于名为“BootstrapperPackage”的不同项目组中)。

Though most examples on the net use "BootstrapperFile" or "BootstrapperPackage", the name is not significant, it just has to line up with the parameter of the bootstrapper generation task - unfortunately consistency of examples in some cases can lead to misconceptions :) 虽然网上的大多数示例都使用“BootstrapperFile”或“BootstrapperPackage”,但名称并不重要,它只需要与引导程序生成任务的参数对齐 - 遗憾的是,在某些情况下,示例的一致性会导致误解:)

Once corrected, the other thing to check is that when building - on both your local machine and on the build server (if you have one) that no warnings are logged - the boostrapper generation task by default will not cause the build to fail if one or more packages can't be located. 一旦纠正,另一件需要检查的是,在构建时 - 在本地计算机和构建服务器上(如果有的话)都没有记录任何警告 - 默认情况下,boostrapper生成任务不会导致构建失败或者找不到更多的包裹。

You will see this in the msbuild logs as: 您将在msbuild日志中看到:

  • warning MSB3155: Item '.NETFramework,Version=v4.0' could not be located in ''. 警告MSB3155:项目'.NETFramework,Version = v4.0'无法位于''。

Easy ways to detect this is the case with your bootstrapper, are: 引导程序的简单方法就是:

  1. Your generated .exe file is unusually small - say 300-400K. 您生成的.exe文件异常小 - 比如300-400K。
  2. Delete your accompany .MSI file, then run the bootstrapper - it will generate a log file (which it provides the path to in an error message). 删除伴随的.MSI文件,然后运行引导程序 - 它将生成一个日志文件(它提供错误消息中的路径)。 The log file will list which packages were checked (to see if they need to be executed) - along with what was executed. 日志文件将列出已检查的软件包(以查看是否需要执行这些软件包)以及执行的内容。 If your package wasn't in the list, it's likely not in the bootstrapper. 如果您的包不在列表中,则可能不在引导程序中。

I used dotnetinstaller for checking and installing pre-requisites. 我使用dotnetinstaller来检查和安装先决条件。 Its very simple and easy to use. 它非常简单易用。 Also it provides the facility to convert msi into exe and attaching UAC prompt. 它还提供了将msi转换为exe并附加UAC提示的功能。 You need to have an configuration file 您需要有一个配置文件

Then in your project in post-build event add this code. 然后在构建后事件的项目中添加此代码。 This will embed your msi and pre-requisite file. 这将嵌入您的msi和先决条件文件。

copy /Y "$(ProjectDir)Files\dotnetfx35setup.exe" "C:\Windows\Temp"
copy /Y $(TargetPath) "C:\Windows\Temp"
"$(SolutionDir)Tools\dotNetInstaller 2.0\Bin\installerLinker.exe" /o:"$(TargetDir)Setup.exe" /t:"$(SolutionDir)Tools\dotNetInstaller 2.0\Bin\dotNetInstaller.exe" /c:"$(ProjectDir)Files\Configuration.xml" /b:"$(ProjectDir)Files\banner.bmp" /Embed+ /Verbose+

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

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