2014-04-24 47 views
0

我的WPF應用程序部署爲ClickOnce使用NANT腳本發佈ClickOnce應用程序

Visual Studio我打開「Project properties/Publish」。

在那裏,我有:

  • 發佈位置
  • 發佈URL
  • 版本
  • 簽名

的問題是,我必須公佈每個版本的測試和生產。 它們之間的區別是屬性publish locationpublish URL。目前,我必須執行兩次流程,同時在發佈生產前更改這些值。

因此,按發佈的結果是包含文件夾「ApplicationFiles」,application manifest文件和setup.exe的文件夾。

然後我決定使用NANT自動化這個過程。

我建立/首先發布的應用程序進行測試(這裏我設置的.csproj文件的位置,發佈文件夾和應用程序varsion)

<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> 

有了這個,我發現,構建不設置出版商。另外我需要更改提供商URL,因爲應用程序也是通過互聯網安裝的(不同的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文件中的值。

考慮到所有上述的我有三個問題:

是否有建設有正確的參數應用的一種方式,所以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> 
+0

在構建和使用控制檯應用程序構建本身之前調用控制檯應用程序對您來說可能是一個可行的解決方案嗎?或者它是南特? – Herdo

回答

0

我能而無需顯式登錄創建正確生成,你在你的問題(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> 

我跑在隊伍城市這些腳本。因爲我使用了發佈目標,所以我不必擔心簽署任何清單。此外,我使用NAnt.Contrib.Tasks.dll中的msbuild任務,您可以在這裏下載NAntContrib

相關問題