【问题标题】:Adding files to Azure cspkg in afterbuild msbuild event?在 afterbuild msbuild 事件中将文件添加到 Azure cspkg?
【发布时间】:2011-07-21 16:06:34
【问题描述】:

我有一个 MVC 应用程序,除了获取已发布的 .cspkg 文件以包含在构建后过程中创建的 css/jscript 之外,我已经在 Azure 上工作(如果我发布到未使用的普通服务器,这将起作用天蓝色)。

在构建后的过程中,我缩小并合并文件,然后将它们添加到部署 zip:

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

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

我需要更改哪些 MSBuild 代码才能执行相同的任务,但改为添加到 cspkg?

【问题讨论】:

  • 我现在使用 Optimization.BundleTable 代替,因此不需要在构建后自己手动缩小/合并 CSS 和 JavaScript。

标签: msbuild azure


【解决方案1】:

这就是我刚才的做法。在此示例中,我有一个 .csproj 文件,它是 Azure 解决方案的一部分,并且我的 C# 项目生成的 dll 需要一个特定的 Xml 文件才能在部署中紧邻它。以下是我的 .csproj 文件中展示该技术的一些 msbuild 片段。您可以将所有这些代码放在 .csproj 文件中 Microsoft.CSharp.targets 的导入下方。

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

-伯尔尼·麦卡蒂

【讨论】:

    【解决方案2】:

    我认为这只是时间问题...确保在发布(打包)步骤发生之前将文件合并、缩小并放入构建中。

    抱歉,我没有更多详细信息;我从来没有尝试过做这种事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多