2011-07-21 34 views
4

我有一個MVC應用程序,我已經從事Azure的工作,除了獲取已發佈的.cspkg文件以包含在afterbuild過程中創建的css/jscript(如果我發佈到不使用Azure的普通服務器)。在afterbuild msbuild事件中將文件添加到Azure cspkg中?

在afterbuild過程中,我再壓縮和合並文件,然後將它們添加到部署郵編:

<PackageLocation>..\Deploy\Website.zip</PackageLocation> 

<PropertyGroup> 
    <CopyAllFilesToSingleFolderForPackageDependsOn> 
    CustomCollectFiles; 
    $(CopyAllFilesToSingleFolderForPackageDependsOn); 
    </CopyAllFilesToSingleFolderForPackageDependsOn> 
</PropertyGroup> 

什麼MSBuild的代碼,我需要爲了做同樣的任務,但是增加了cspkg,而不是改變?

+0

有過任何成功? –

+0

我現在使用Optimization.BundleTable來代替,所以不需要在afterbuild中自己手動縮小/合併CSS和JavaScript。 – KevinUK

回答

0

我認爲這只是一個時間問題......確保文件在發佈(包裝)步驟發生之前進行組合,縮小和放置到構建中。

對不起,我沒有更多的細節;我從來沒有嘗試過這樣的事情。

3

這就是我剛剛做到的。在這個例子中,我有一個.csproj文件,它是Azure解決方案的一部分,並且我的C#項目生成的dll需要一個特定的Xml文件才能在部署中位於它旁邊。以下是我的.csproj文件中的一些msbuild片段,顯示了該技術。您可以將所有這些代碼放在Microsoft.CSharp.targets導入到.csproj文件中。

<!-- Identify the Xml input file that must be deployed next to our dll. --> 
<ItemGroup> 
    <SpecialXmlFileItem Include="c:\temp\MySpecialFile.xml" /> 
</ItemGroup> 

<PropertyGroup> 
    <!-- In my case I needed the as-deployed Xml filename to be fixed and yet I wanted it to be possible 
     to provide any filename at all to be provided as the source. Here we are defining the fixed, 
     as-deployed filename. --> 
    <AsDeployedXmlFilename>MyServiceStorageConfig.xml</AsDeployedXmlFilename> 

    <!-- Wire our own AddFilesToProjectDeployment target into the GetCopyToOutputDirectoryItems 
     target. That target is evaluated not only as part of normal .csproj evaluation, but also as part 
     of .ccproj evaluation. It is how the .ccproj manages to interrogate your dll producing projects 
     about all of the project files that need to be packaged. --> 
    <GetCopyToOutputDirectoryItemsDependsOn> 
     AddFilesToProjectDeployment; 
     $(GetCopyToOutputDirectoryItemsDependsOn) 
    </GetCopyToOutputDirectoryItemsDependsOn> 
</PropertyGroup> 

<Target Name="AddFilesToProjectDeployment"> 
    <Error Condition="!Exists('@(SpecialXmlFileItem)')" 
     Text="The all important and very special XML file is not found: %(SpecialXmlFileItem.ItemSpec)" /> 
    <ItemGroup> 
    <ContentWithTargetPath Include="@(SpecialXmlFileItem->'%(FullPath)')"> 
     <!-- In my case I wanted to deploy my xml file right next to my .dll, so I included no relative 
     path information in the below value of TargetPath, just the simple filename. But, I think if you 
     included relative path information in the below value that it would be preserved in the deployment. --> 
     <TargetPath>$(AsDeployedXmlFilename)</TargetPath> 
     <CopyToOutputDirectory>Always</CopyToOutputDirectory> 
    </ContentWithTargetPath> 
    </ItemGroup> 
</Target> 

-Bern麥卡蒂

相關問題