首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AjaxMin在Azure网站上不起作用

AjaxMin在Azure网站上不起作用
EN

Stack Overflow用户
提问于 2013-02-20 05:49:32
回答 2查看 316关注 0票数 0

我使用BuildTask在运行时自动缩小javascript。此构建任务在.csproj文件中指定。

是否可以在Azure站点上使用构建任务?我是不是遗漏了什么?我已经确保没有像本(http://www.asp.net/ajaxlibrary/AjaxMinQuickStart.ashx)教程所建议的那样在源代码控制中包含Azure文件,但我想知道是否有什么特定于.min.js的东西需要我设置。

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-21 00:01:46

我已经让它在我的项目中正常工作了。我将告诉您我是如何做到这一点的,尽管这可能不是最简单或最直接的方法。

在我们开始之前,能够在不实际部署的情况下检查您的精简文件是否包含在Azure部署包中是很有帮助的。这很容易做到。.cspkg文件实际上是一个zip格式的文件,所以您可以使用任何zip归档程序打开它。(我喜欢使用7Zip,因为右键单击-> Open Archive命令不需要重命名文件,但您可以使用Windows Explorer、WinRAR等。)在.cspkg中,您将看到另一个扩展名为.cssx的大文件。这也是一个压缩文件。在.cssx中,您将发现一个sitesroot文件夹,其中包含您要部署的每个网站的子目录,其中将包含所有实际的网站文件。所以你可以查看一下,看看有哪些文件被部署到Azure上。

首先,尝试编辑web项目的项目文件(包含所有Javascript/CSS文件的文件)。您可以使用记事本,或者在Visual Studio中右键单击项目,选择“卸载项目”,然后再次右键单击并选择“编辑”。在项目文件中,插入如下所示的节:

代码语言:javascript
复制
<ItemGroup>
    <!-- Copy over all the minified CSS & JS to the output directory-->
    <Content Include="**\*.min.css" />
    <Content Include="**\*.min.js" />
</ItemGroup>

然后重新加载项目,重新打包,并查看您的文件是否包含在.cspkg文件中。如果是,那么你就完蛋了。

如果不是,还有其他几件事需要检查。您的缩减可能没有在正确的构建阶段运行。我的缩小目标如下所示:

代码语言:javascript
复制
<Target Name="PrepWebApp" Condition="$(Configuration)=='Release'" AfterTargets="AfterBuild">

如果这仍然不起作用,并且您的Web角色中有多个站点和/或虚拟应用程序,那么打包步骤可能没有为所有站点运行。因此,当你打包你的项目以便部署到Azure时,它可能仍然没有运行缩减步骤(以及web.config转换,以及其他一些东西)。如果是这种情况,请参阅this blog post以获取修复它的方法。

为了防止这篇博客文章消失,我将在这里复制最相关的部分。您可以将此代码放入您的web角色的.ccproj文件中(更改适当的部分以匹配您的项目结构):

代码语言:javascript
复制
<PropertyGroup>
  <!-- Inject the publication of "secondary" sites into the Windows Azure build/project packaging process. -->
  <CoreBuildDependsOn>
    CleanSecondarySites;
    PublishSecondarySites;
    $(CoreBuildDependsOn)
  </CoreBuildDependsOn>
  <!-- This is the directory within the web application project directory to which the project will be "published" for later packaging by the Azure project. -->
  <SecondarySitePublishDir>azure.publish\</SecondarySitePublishDir>
</PropertyGroup>
<!-- These SecondarySite items represent the collection of sites (other than the web application associated with the role) that need special packaging. -->
<ItemGroup>
  <SecondarySite Include="..\WebApplication1\WebApplication1.csproj" />
  <SecondarySite Include="..\WebApplication2\WebApplication2.csproj" />
</ItemGroup>
<Target Name="CleanSecondarySites">
  <RemoveDir Directories="%(SecondarySite.RootDir)%(Directory)$(SecondarySitePublishDir)" />
</Target>
<Target Name="PublishSecondarySites" Condition="'$(PackageForComputeEmulator)' == 'true'
                      Or '$(IsExecutingPublishTarget)' == 'true' ">
  <!--
    Execute the Build (and more importantly the _WPPCopyWebApplication) target to "publish" each secondary web application project.

    Note the setting of the WebProjectOutputDir property; this is where the project will be published to be later picked up by CSPack.
  -->
  <MSBuild Projects="%(SecondarySite.Identity)" Targets="Build;_WPPCopyWebApplication" Properties="Configuration=$(Configuration);Platform=$(Platform);WebProjectOutputDir=$(SecondarySitePublishDir)" />
票数 1
EN

Stack Overflow用户

发布于 2013-02-20 06:12:55

生成项目时,生成任务将在Visual Studio中运行。你需要确保缩小的文件也被部署到Azure。

我猜可能是因为项是在构建时生成的,所以它不是项目本身的一部分,并且部署步骤忽略了这一点。

请检查所使用的部署系统是否将包括所有脚本文件,而不仅仅是项目本身中的脚本文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14968131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档