2013-02-19 49 views
0

我正在使用Microsoft的AjaxMin来缩小我的网站上的JavaScript,该网站由Azure托管。我正在使用BuildTask在运行时自动缩小JavaScript。该构建任务在.csproj文件中指定。AjaxMin不能在Azure站点上工作

该进程正在处理我的本地环境,但是,当我部署到Azure站点时它不起作用。天蓝色的网站抛出404:文件未找到错误,当我尝试引用.js文件的缩小版本。

是否可以在Azure站点上使用构建任务?有什么我失踪?我确定不要在源代码管理中包含.min.js文件,因为这(http://www.asp.net/ajaxlibrary/AjaxMinQuickStart.ashx)教程建议,但我想知道是否有任何特定于Azure的东西需要设置。

谢谢!

回答

1

我已经在我的项目中正常工作。我会告诉你我是怎么做到的,尽管这可能不是最简单或最直接的方法。

在我们开始之前,能够检查您的缩小文件是否包含在Azure部署软件包中而不实际部署是有帮助的。这很容易做到。 .cspkg文件实际上是一个zip格式的文件,因此您可以使用任何zip压缩文件打开它。 (我喜欢为此使用7Zip,因为右键单击 - > Open Archive命令不需要您重命名文件,但可以使用Windows资源管理器,WinRAR等)。在.cspkg内部,您会看到另一个大文件扩展名为.cssx。这也是一个zip文件。在.cssx的内部,您会发现一个sitesroot文件夹,其中包含您正在部署的每个网站的子目录,其中将包含您的所有实际网站文件。因此,您可以在那里查看哪些文件正在部署到Azure。

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

<ItemGroup> 
    <!-- Copy over all the minified CSS & JS to the output directory--> 
    <Content Include="**\*.min.css" /> 
    <Content Include="**\*.min.js" /> 
</ItemGroup> 

然后重新加载项目,重新包装,看看你的文件都包含在.cspkg文件。如果他们是,那么你就完成了。

如果没有,还有其他一些事情要检查。您的缩小可能无法在正确的构建阶段运行。我的微小目标看起来是这样的:

<Target Name="PrepWebApp" Condition="$(Configuration)=='Release'" AfterTargets="AfterBuild"> 

如果仍然没有工作,你的Web角色有多个站点和/或它的虚拟应用程序,它可能是在包装的步骤没有运行的所有网站。因此,当您将项目打包为部署到Azure时,它可能仍未运行缩小步骤(以及web.config转换和其他一些操作)。如果是这种情况,请参阅this blog post以解决问题。

万一那个博客中消失了,我会在这里复制最相关的位。你会把这在.ccproj文件为您的Web角色(在适当的位改变,以匹配您的项目结构):

<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)" /> 
0

当您构建项目时,构建任务将在Visual Studio中运行。您需要确保缩小的文件也正在部署到Azure。

我猜测,也许是因为该项目是在构建时生成的,它不是项目本身的一部分,并且部署步骤会忽略它。

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

+0

感谢您的答复。我不确定我想要在项目中包含.min.js文件。据微软称:“如果你在项目中包含缩小的文件,并使用源代码控制,那么你会遇到问题,当文件签出源代码控制的,他们用自己的只读属性设置如果选中了你尝试做一个构建,微软的Ajax Minifier会产生一个错误,当它试图写入只读文件。”似乎Azure应该在每次构建之后创建文件,而不是从本地环境中检入文件 – user1521567 2013-02-20 15:08:51

相关问题