【问题标题】:Wrong version of aspnetcompiler when using msbuild 4.0使用 msbuild 4.0 时的 aspnetcompiler 版本错误
【发布时间】:2010-07-22 18:51:14
【问题描述】:

我正在尝试使用自定义 msbuild 文件中的 AspNetCompiler 任务来预编译 asp .net 4.0 网站。但是,当我运行时:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe custom.msbuild /t:PrecompileWeb

它使用 v2.0.50727 aspnet_compiler。有没有办法强制它使用 v4.0.30319 aspnet_compiler?我问的原因是因为我收到了这个错误:

ASPCONFIG: Unrecognized configuration section system.web.extensions.

但是,如果我运行:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -p .\My.Web.Site -f .\.PRECOMPILATION -v /

它运行良好,这是有道理的,因为我在 web.config 中使用 system.web.extensions 而 2.0 aspnet_compiler 不知道那是什么。

【问题讨论】:

    标签: msbuild msbuild-task


    【解决方案1】:

    ToolPath 适用于 AspNetCompiler 任务,但正确的做法是在 Project 元素上设置 ToolsVersion="4.0" 属性 - 这将导致所有内置工具使用正确的版本并且不需要路径的硬编码。

    【讨论】:

    • +1 这对我的 MVC3 站点的自定义构建项目很有用。该项目是 2008 版本的一个端口(尽管除了添加此属性之外实际上不需要任何更改)。似乎是 MSBuild 4 中的一个错误 - 没有工具版本会导致某些工具默认为 v2!
    【解决方案2】:

    好吧,我碰巧在搜索更多内容,并在这里找到了我自己的问题的答案:

    http://blogs.msdn.com/b/webdevtools/archive/2010/05/14/the-aspnet-compiler-build-task-in-visual-studio-2010-asp-net-mvc-2-projects.aspx

    我最终使用的是 AspNetCompiler 任务的 ToolPath 属性,如下所示:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <Target Name="PrecompileWeb">
            <AspNetCompiler
                VirtualPath="/MyWebSite"
                PhysicalPath="c:\inetpub\wwwroot\MyWebSite\"
                TargetPath="c:\precompiledweb\MyWebSite\"
                Force="true"
                Debug="true"
                ToolPath="C:\Windows\Microsoft.NET\Framework\v4.0.30319\"
            />
        </Target>
    </Project>
    

    【讨论】:

    • @VladL 不,它确实存在,只是在基类 ToolTask​​Extension 中。请检查这个link
    猜你喜欢
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2016-07-01
    • 1970-01-01
    • 2014-11-27
    • 2019-01-31
    • 1970-01-01
    相关资源
    最近更新 更多