使用MSBuild从命令行生成ClickOnce部署的setup.exe

使用MSBuild从命令行生成ClickOnce部署的setup.exe,msbuild,clickonce,Msbuild,Clickonce,我有一个MSBuild脚本,它构建我的windows窗体应用程序,生成应用程序清单并对其签名,然后生成部署清单。脚本还为我生成publish.htm文件 现在我需要生成setup.exe文件,到目前为止,我还不能弄清楚VS是如何生成它的。如何使用MSBuild脚本生成setup.exe文件 提前感谢您的帮助 您可以使用内置的MSBuild任务 当您从VisualStudio进行发布时,ClickOnce也会使用此功能 请查看C:\Windows\Microsoft.NET\Framework\\

我有一个MSBuild脚本,它构建我的windows窗体应用程序,生成应用程序清单并对其签名,然后生成部署清单。脚本还为我生成publish.htm文件

现在我需要生成setup.exe文件,到目前为止,我还不能弄清楚VS是如何生成它的。如何使用MSBuild脚本生成setup.exe文件

提前感谢您的帮助

您可以使用内置的MSBuild任务

当您从VisualStudio进行发布时,ClickOnce也会使用此功能

请查看C:\Windows\Microsoft.NET\Framework\\Microsoft.Common.Targets以查看发生的确切情况

查看_DeploymentGenerateBottrapper目标

您的CSharp项目文件包含一些项和属性,此目标使用这些项和属性来确定:

  • 如果要生成引导程序(BootstrapperEnabled属性)
  • 要为其生成引导程序的包(BootstrapperPackage项目组)
  • 安装包的位置(BootstrapperComponentsLocation属性)

  • 希望这是有道理的。只需做一点工作,您就可以使用MSBuild文件实现从Visual Studio发布时发生的事情。

    要使用MSBuild的标志有:

    /target:publish
    
    以及:

    请注意,您必须在发布目录上有一个尾随的
    \
    ,否则它只需在发布时执行相关步骤(即构建),而不会实际生成安装程序

    您可能对
    msbuild
    npm包感兴趣:

    var msbuild = require('msbuild');
    var path = require('path');
    
    // Config
    var source = 'source/Bar/Bar.App/Bar.App.csproj';
    var deploy = path.join(__dirname, 'deploy');
    
    // Build the project
    var builder = new msbuild();
    builder.sourcePath = source;
    builder.overrideParams.push('/p:PublishDir=' + deploy + "\\"); // <-- Installer
    builder.overrideParams.push('/Target:rebuild;publish');
    builder.overrideParams.push('/P:Configuration=Release');
    builder.overrideParams.push('/P:verbosity=diag');
    builder.overrideParams.push('/P:Platform=x86');
    builder.overrideParams.push('/fl');
    builder.overrideParams.push('/flp:logfile=build.log;verbosity=diagnostic');
    builder.publish();
    

    不需要powershell

    你的setup.exe有哪些变化要求在每次生成时都生成它?我不一定在每次生成时都生成它。我打算为不同的应用程序重用该脚本,因此如果是新的应用程序,我希望该脚本能够生成设置。谢谢,我会看一看。为了解决这个问题,当我的问题没有得到回答时,我将VisualStudio生成的文件复制到我的一个部署中,并重新使用它。它似乎工作得很好,但这个任务可能就是我想要的。即使它不能解决我的问题,它仍然是我学到的另一项任务:)
    var msbuild = require('msbuild');
    var path = require('path');
    
    // Config
    var source = 'source/Bar/Bar.App/Bar.App.csproj';
    var deploy = path.join(__dirname, 'deploy');
    
    // Build the project
    var builder = new msbuild();
    builder.sourcePath = source;
    builder.overrideParams.push('/p:PublishDir=' + deploy + "\\"); // <-- Installer
    builder.overrideParams.push('/Target:rebuild;publish');
    builder.overrideParams.push('/P:Configuration=Release');
    builder.overrideParams.push('/P:verbosity=diag');
    builder.overrideParams.push('/P:Platform=x86');
    builder.overrideParams.push('/fl');
    builder.overrideParams.push('/flp:logfile=build.log;verbosity=diagnostic');
    builder.publish();
    
    npm install msbuild
    node builder.js