Search code examples
c#clickoncepublishbootstrapperprerequisites

ClickOnce prerequisite for "ASP.NET Core Runtime 6.0.10 x64"


I am using ClickOnce in Visual studio. I can set ".net desktop runtime 6.0.10 (x64)" and "".net runtime 6.0.10 (x64)" prerequisite. I also need "ASP.NET Core Runtime 6.0.10". If I install it manually my program runs, but the idea it should be installed automatically. What am I missing? enter image description here


Solution

  • I asked MS to add "ASP.NET Core Runtime 6.0.10 x64" prerequisite, the answer was "we are not planning on adding ClickOnce bootstrapper support for Asp.Net due to low demand". I have done a lot of research and I was able to do it myself. You need three files.

    product.xml:

    <?xml version="1.0" encoding="utf-8" ?> 
    
    <!-- Directory structure: aspnet7runtime_x86\product.xml, aspnet7runtime_x86\NetCoreCheck.exe, aspnet7runtime_x86\en\package.xml 
    Copy this structure into c:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages -->
    
    <!-- A unique ProductCode is needed, this value will be displayed at the prerequisite list. -->
    <Product xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper" ProductCode="Microsoft.AspNetCore.Runtime.7.0.0.x64">
    
      <!-- Defines list of files to be copied on build -->
      <PackageFiles CopyAllPackageFiles="false">
        <!-- Go to https://dotnet.microsoft.com/en-us/download select the version, select the windows x64 installer, copy the direct link. Update the Name and the HomeSite. 
        You do not have to set the PublicKey but if you do then select the steps from https://foxlearn.com/articles/adding-custom-prerequisites-to-visual-studio-setup-project-468.html -->
        <PackageFile Name="aspnetcore-runtime-7.0.0-win-x64.exe"
                     HomeSite="https://download.visualstudio.microsoft.com/download/pr/388543cf-e110-4425-be62-2dfa1635586c/fab629ebe2c7b2edfa0f2ee9171de26b/aspnetcore-runtime-7.0.0-win-x64.exe"
                     PublicKey="0" />
         <!-- You can fin NetCoreCheck.exe at <VS install directory>\MSBuild\Microsoft\VisualStudio\BootstrapperPackages\net7coreruntime_x64  -->
        <PackageFile Name="NetCoreCheck.exe" />
      </PackageFiles>
    
      <!-- Run the NetCoreCheck tool that will determine if the necessary framework is installed -->
      <InstallChecks>
        <!-- Useage of NetCoreCheck: https://github.com/dotnet/deployment-tools/issues/84 -->
        <ExternalCheck Property="NetCoreCheck" PackageFile="NetCoreCheck.exe" Arguments="Microsoft.AspNetCore.App 7.0.0"/>
      </InstallChecks>
    
      <!-- Defines how to invoke the setup for the Asp.NET Runtime 7.0 -->
      <Commands Reboot="Defer">
        <Command PackageFile="aspnetcore-runtime-7.0.0-win-x64.exe" Arguments=' /q '>
    
          <!-- These checks determine whether the package is to be installed -->
          <InstallConditions>
            <!-- Block install on less than Windows 7 RTM -->
            <FailIf Property="VersionNT" Compare="VersionLessThan" Value="6.1.0" String="InvalidPlatformWinNT"/>
            <!-- NetCoreCheck returning 0 means the runtime is already installed -->
            <BypassIf Property="NetCoreCheck" Compare="ValueEqualTo" Value="0"/>
            <!-- Block install if user does not have admin privileges -->
            <FailIf Property="AdminUser" Compare="ValueEqualTo" Value="false" String="AdminRequired"/>
          </InstallConditions>
    
          <ExitCodes>
            <ExitCode Value="0" Result="Success"/>
            <ExitCode Value="3010" Result="SuccessReboot"/>
            <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />
          </ExitCodes>
    
        </Command>
      </Commands>
    </Product>
    

    package.xml:

    <?xml version="1.0" encoding="utf-8" ?>
    <Package xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper" Name="DisplayName" Culture="Culture">
    
      <!-- Defines a localizable string table for error messages-->
      <Strings>
        <String Name="DisplayName">ASP.NET Core Runtime 7.0.0 (x64)</String>
        <String Name="Culture">en</String>
        <String Name="AdminRequired">You do not have the permissions required to install the ASP.NET Core Runtime 7.0.0. Please contact your administrator.</String>
        <String Name="GeneralFailure">A failure occurred attempting to install the ASP.NET Core Runtime 7.0.0.</String>
        <String Name="InvalidPlatformWinNT">Installation of the Microsoft ASP.NET Core Runtime 7.0.0 is not supported on this operating system.</String>
      </Strings>
    </Package>
    
    1. Create a directory structure:

      • aspnet7runtime_x86\product.xml
      • aspnet7runtime_x86\NetCoreCheck.exe
        • find it at at <VS install directory>\MSBuild\Microsoft\VisualStudio\BootstrapperPackages\net7coreruntime_x64
      • aspnet7runtime_x86\en\package.xml
    2. Copy this structure into c:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages. Now the new dependency should appear in VS

      • you need admin rights
    3. If there is a new version then you should create a new directory structure with modified xml files.

    These were the links which helped me