【问题标题】:Publishing ClickOnce application with NANT script使用 NANT 脚本发布 ClickOnce 应用程序
【发布时间】:2014-04-24 07:11:02
【问题描述】:

我的WPF 应用程序使用ClickOnce 部署。

Visual Studio 我打开“Project properties / Publish”。

我有:

  • 发布位置
  • 发布网址
  • 版本
  • 签名

问题是,我必须发布每个版本以进行测试和生产。 它们之间的区别在于属性publish locationpublish URL。目前我必须执行两次该过程,同时在发布生产之前更改值。

所以按下发布的结果是一个包含文件夹“ApplicationFiles”的文件夹、application manifest 文件和一个setup.exe

然后我决定使用 NANT 自动化这个过程。

我首先构建/发布应用程序进行测试(这里我设置 .csproj 文件位置、发布文件夹和应用程序变量)

<target name="BuildTestApplication" depends="Clean" description="Build">
  <echo message="Building..." />    
  <exec program="${msbuildExe}" workingdir="." verbose="true">
    <arg value="${projectFile}" />
    <arg value="/target:Clean;Publish" />
    <arg value="/p:PublishDir=${testPublishFolder}" />
    <arg value="/p:ApplicationVersion=${version}" />
    <arg value="/p:Publisher=&quot;${publisherName}&quot;" />
  </exec>
  <echo message="Built" />
</target>

有了这个,我发现 build 没有设置发布者。另外,我需要更改提供程序 URL,因为该应用程序也是通过 Internet 安装的(用于测试和生产的 URL 不同)。所以我做到了:

<target name="UpdateTestApplication" depends="BuildTestApplication" description="Update">
  <echo message="Updating..." />    
  <exec program="${mageExe}" workingdir="." verbose="true">
    <arg value="-Update" />
    <arg value="${testPublishFolder}/EdpClient.application" />
    <arg value="-ProviderUrl" />
    <arg value="&quot;${testPublishUrl}&quot;" />
    <arg value="-Publisher" />
    <arg value="&quot;${publisherName}&quot;" />
  </exec>
  <echo message="Updated" />
</target>

有了这个,我用正确的值更新了application manifest 文件(PublisherProviderUrl)...

我对生产构建执行相同的操作,这意味着我将应用程序构建到另一个文件夹并使用不同的 ProviderUrl 更新它并添加 Publisher,因为它必须包含在每个 mage 更新中...

现在问题出在 setup.exe 文件上。 Setup.exe 在构建时生成,它从.csproj 文件中获取值。

考虑到以上所有问题,我有三个问题:

1. 有没有办法使用正确的参数构建应用程序,所以 setup.exe 将包含正确的值?

2. 另外,我将如何在构建之前更新程序集信息(参数版本)?从VS 发布时,我需要在“Probject properties / Application / Assembly Information”上更新它

3. 我注意到当从VS 发布时,应用程序清单文件也会在“Application Files”文件夹中生成,而使用MSBUILD 发布时不会。这是为什么呢?

在此先感谢您并致以最诚挚的问候,no9

编辑:

我像这样解决了问题#2

<!--UPDATE ASSEMBLY INFORMATION BEFORE BUILD-->
  <target name="UpdateAssemblyInfo">
    <asminfo output="${assemblyInfoFile}" language="CSharp">
      <imports>
        <import namespace="System" />
        <import namespace="System.Reflection" />
        <import namespace="System.Resources" />
        <import namespace="System.Runtime.CompilerServices" />
        <import namespace="System.Runtime.InteropServices" />
        <import namespace="System.Windows" />
      </imports>
      <attributes>
        <attribute type="AssemblyTitleAttribute" value="some value" />
        <attribute type="AssemblyDescriptionAttribute" value="some value" />
        <attribute type="AssemblyConfigurationAttribute" value="some value" />
        <attribute type="AssemblyCompanyAttribute" value="some value" />
        <attribute type="AssemblyProductAttribute" value="some value" />
        <attribute type="AssemblyVersionAttribute" value="some value" />
        <attribute type="AssemblyFileVersionAttribute" value="some value" />
        <attribute type="AssemblyCopyrightAttribute" value="some value" />
        <attribute type="AssemblyTrademarkAttribute" value="some value" />
        <attribute type="AssemblyCultureAttribute" value="some value" />
        <attribute type="CLSCompliantAttribute" value="boolean value" />
        <attribute type="ComVisibleAttribute" value="boolean value" />
      </attributes>
    </asminfo>
    <echo file="${assemblyInfoFile}" append="true">
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page, 
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries)
)]
    </echo>
    <echo message="Updated" />
  </target>

意思是我在构建之前覆盖Assembly.info 文件并添加相关值。

问题#3是这样的:

   <!--COPY APPLICATION MANIFEST TO APPLICATIONFILES FOLDER-->
      <target name="CopyTestApplicationManifestToApplicationFilesFolder"     depends="Dependency target name" description="Update">
      <echo message="Copying..." />
      <copy 
        file="source file"
        tofile="target file" />
       <echo message="Copied" />
     </target>

【问题讨论】:

  • 在构建之前调用控制台应用程序并为构建本身使用控制台应用程序对您来说是一种可能的解决方案吗?还是必须是 NANT?

标签: visual-studio-2010 msbuild clickonce nant mage


【解决方案1】:

我能够创建正确生成您在问题中提到的资产(setup.exe、应用程序文件夹等)的任务,而无需显式签署清单。

“clean_and_publish_application”任务执行以下操作

  1. 清理项目
  2. 重建项目
  3. 发布项目**这里我提供了几个参数来指定我的发布网址、BootstrapperSDKPath、应用程序版本和应用程序修订版

    <target name="clean_and_publish_application" description="Build the application.">
    <echo message="Clean the build directory"/>
    <msbuild project ="${src.dir}\${target.assembly.name}.csproj">
             <arg value="/property:Configuration=Debug;outdir=bin\Debug" />
             <arg value="/t:clean" />
     </msbuild>
     <echo message="Rebuild the application"/>
     <msbuild project ="${src.dir}\${target.assembly.name}.csproj">
     <arg value="/property:Configuration=Debug;outdir=bin\Debug" />
     <arg value="/t:rebuild" />
    </msbuild>
    <echo message="Publish the application"/>
    <msbuild project ="${src.dir}\${target.assembly.name}.csproj">
    <arg value="/p:publishurl=${publish.url};
    GenerateBootstrapperSdkPath=
    C:\Program Files (x86)\Microsoft  SDKs\Windows\v8.0A\Bootstrapper\;
    ApplicationVersion=${app.version};
    ApplicationRevision=${app.revision}" />
    <arg value="/t:publish" />
    </msbuild>
    </target>
    

创建 setup.exe 文件需要 BootstrapperSdkPath 属性。我对位置进行了硬编码,因为它不会改变。 MSBuild 正在该目录中寻找 setup.bin 文件。

ApplicationVersion 属性的格式例如为 2.0.0.%2a

ApplicationRevision 属性被格式化为数字,例如 24(这些值是我们在 Visual Studio 中看到的发布版本。我从未真正更新过 AssemplyInfo.cs 文件。)

您在 .csproj 文件中看到的任何属性都可以作为 msbuild 的参数传递。我发现这个文档很有帮助 MSBuild Command-Line Reference

除了将文件实际复制到您的发布网址之外,上述任务可以完成您需要的一切(仍在寻找答案)。所以我只是手动复制发布创建的 app.config 目录中的所有文件

<target name="copy_src">
<echo message="Copying app.config folder"/>
    <copy todir="${publish.url}" overwrite="true"  failonerror="true">
        <fileset basedir="${src.dir}\${app.config.location}">
            <include name="**" />
        </fileset>
    </copy>
</target>

我在 Team City 中运行这些脚本。因为我使用了发布目标,所以我不必担心签署任何清单。另外,我使用来自 NAnt.Contrib.Tasks.dll 的 msbuild 任务,您可以在此处下载 NAntContrib

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-26
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    相关资源
    最近更新 更多