2012-10-05 51 views
18

MSBuild ExtensionのZipタスクを使用して、すべてのビルド時にソースコードの一部を圧縮することにしました。MSBuildエクステンションのZipタスクの使い方は?

はしかし、これではない作品:私は、このエラーの原因がわからない

The "MSBuild.ExtensionPack.Compression.Zip" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "c:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.

<UsingTask TaskName="MSBuild.ExtensionPack.Compression.Zip" AssemblyFile="MSBuild.ExtensionPack.dll" /> 
<Target Name="AfterBuild"> 
    <CallTarget Targets="ZipSourceFiles" /> 
</Target> 
<Target Name="ZipSourceFiles" Condition="'$(ConfigTransform)'=='ImRunningOnTheServer'"> 
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" CompressFiles="c:\source.txt" ZipFileName="C:\target.zip"/> 
</Target> 

私は、次のエラーメッセージが表示されましたか?何か案が? MSBuild Community Tasksため

+0

* MSBuild Extension Packには*が含まれていますか?私はそれを使ったことはありませんが、代わりに[MSBuild Community Tasks](https://github.com/loresoft/msbuildtasks)の実例を提供することができます。 –

+0

このパックである必要はありません。ファイルを正しく圧縮するだけです:) – Zsolt

答えて

32

例:

<Import Project="lib\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" /> 

<Target Name="Zip"> 
     <CreateItem Include="YourSourceFolder\*.*" > 
       <Output ItemName="ZipFiles" TaskParameter="Include"/> 
     </CreateItem> 
     <Zip ZipFileName="YourZipFile.zip" WorkingDirectory="YourSourceFolder" Files="@(ZipFiles)" /> 
</Target> 

あなたはより多くの例が必要な場合は、私のプロジェクトの1からhere is a complete working MSBuild file

+0

ありがとう!それはうまくいった! – Zsolt

+0

実際にそのプロジェクトの物理レイアウトが好きです。何年も.NETに取り組んできましたが、デフォルトのVSセットアップとは何か異なることは考えていませんでした。将来のプロジェクトを構築する方法については、ここを突き詰めることになります。間違いなく、物事を見る私の方法を変えます。 –

+0

私のレイアウトには何が特別な意味ですか?すべて私のプライベートプロジェクトはこれに似ていますが、正直なところ...私は私の典型的なプロジェクトレイアウトについて特別なことは考えていませんでした。 –

4

こちらはMSBuild Community Tasksの代替です。 .net 4.5.1を使用している場合、System.IO.Compression関数をUsingTaskに埋め込むことができます。この例では、ZipFile.CreateFromDirectoryが使用されています。

<Target Name="Build"> 
    <ZipDir 
    ZipFileName="MyZipFileName.zip" 
    DirectoryName="MyDirectory" 
    /> 
</Target> 

<UsingTask TaskName="ZipDir" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll"> 
    <ParameterGroup> 
    <ZipFileName ParameterType="System.String" Required="true" /> 
    <DirectoryName ParameterType="System.String" Required="true" /> 
    </ParameterGroup> 
    <Task> 
    <Reference Include="System.IO.Compression.FileSystem" /> 
    <Using Namespace="System.IO.Compression" /> 
    <Code Type="Fragment" Language="cs"><![CDATA[ 
     try 
     { 
     Log.LogMessage(string.Format("Zipping Directory {0} to {1}", DirectoryName, ZipFileName)); 
     ZipFile.CreateFromDirectory(DirectoryName, ZipFileName); 
     return true; 
     } 
     catch(Exception ex) 
     { 
     Log.LogErrorFromException(ex); 
     return false; 
     } 
    ]]></Code> 
    </Task> 
</UsingTask> 
関連する問題