Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 网站编译在MSBuild中失败,但可在Visual Studio中运行_.net_Msbuild - Fatal编程技术网

.net 网站编译在MSBuild中失败,但可在Visual Studio中运行

.net 网站编译在MSBuild中失败,但可在Visual Studio中运行,.net,msbuild,.net,Msbuild,当我尝试使用MSBuild来构建VS2010解决方案(包括网站项目)时,我遇到了MSBuild任务的奇怪行为。如果我在VisualStudio2010中打开该解决方案并尝试编译它,它就会工作。但是,如果我尝试从MSBuild脚本编译它,它将失败并出错 我已经追踪到一个事实,即在网站目录中有一个用户控件,它不使用代码隐藏 复制步骤: 1.)想象你有一个简单的解决方案。只需一个网站和两个用户控件: web\Controls\HelpButton.ascx: <%@ Control Langua

当我尝试使用MSBuild来构建VS2010解决方案(包括网站项目)时,我遇到了MSBuild任务的奇怪行为。如果我在VisualStudio2010中打开该解决方案并尝试编译它,它就会工作。但是,如果我尝试从MSBuild脚本编译它,它将失败并出错

我已经追踪到一个事实,即在网站目录中有一个用户控件,它不使用代码隐藏

复制步骤:

1.)想象你有一个简单的解决方案。只需一个网站和两个用户控件:

web\Controls\HelpButton.ascx:

<%@ Control Language="C#" ClassName="HelpButton" %>

<script runat="server">
    private string _helpUrl;
    public string HelpUrl
    {
        get { return _helpUrl; }
        set { _helpUrl = value; }
    }

</script>
VS2010可以毫无问题地构建此网站

2.)使用以下MSBuild:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Build">

<PropertyGroup>
<SolutionProperties>Configuration=Release</SolutionProperties>
</PropertyGroup>

<Target Name="Build" DependsOnTargets="">

 <MSBuild Projects="BuildTest.sln" Targets="Build" Properties="$(SolutionProperties)" RebaseOutputs="true">
  </MSBuild>
    </Target>
</Project>
在我看来,如果它以错误的顺序编译用户控件,“HelpButton”放在“TestUserControl”上,“TestUserControl”为“HelpButton”对象的属性赋值。 这是已知的问题吗?有什么建议可以解决这个问题吗

一个对我不起作用的解决方法是从MSBuild脚本执行devenv.exe,然后让devenv.exe生成解决方案。它成功地编译了它,但问题是我不能以这种方式发送其他MSBuild属性

多谢各位

Edit:直接针对解决方案文件执行msbuild命令时的输出:

c:\Tmp\MSBuildIssue>msbuild.exe BuildTest.sln /target:Build /p:Configuration="Debug",Platform="Any CPU" 


Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.235]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 9/12/2011 12:05:38 PM.
Project "c:\Tmp\MSBuildIssue\BuildTest.sln" on node 1 (Build target(s)).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|Any CPU".
Project "c:\Tmp\MSBuildIssue\BuildTest.sln" (1) is building "c:\Tmp\MSBuildIssue\WebSite.metaproj" (2) on node 1 (default targets).
Build:
  C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -v /WebSite -p WebSite\ -u -f -d PrecompiledWeb\WebSite\ 
c:\Tmp\MSBuildIssue\WebSite\AnotherFolder\TestUserControl.ascx.cs(12): error CS1061: 'System.Web.UI.UserControl' does not contain a definition for 'HelpUrl' and no extension method 'HelpUrl' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?) [c:\Tmp\MSBuildIssue\WebSite.metaproj]
Done Building Project "c:\Tmp\MSBuildIssue\WebSite.metaproj" (default targets) -- FAILED.
Done Building Project "c:\Tmp\MSBuildIssue\BuildTest.sln" (Build target(s)) -- FAILED.

Build FAILED.

"c:\Tmp\MSBuildIssue\BuildTest.sln" (Build target) (1) ->
"c:\Tmp\MSBuildIssue\WebSite.metaproj" (default target) (2) ->
(Build target) -> 
  c:\Tmp\MSBuildIssue\WebSite\AnotherFolder\TestUserControl.ascx.cs(12): error CS1061: 'System.Web.UI.UserControl' does not contain a definition for 'HelpUrl' and no extension method 'HelpUrl' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?) [c:\Tmp\MSBuildIssue\WebSite.metaproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.77

这一行怎么样?最后,我使用了AspNetCompiler任务而不是MSBuild。令人惊讶的是,AspNetCompiler在MSBuild任务失败的情况下工作

<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"
        />
    </Target>

我必须用实际生产解决方案解决的唯一问题是,我们的解决方案包含许多其他项目(程序集、可执行文件),而不仅仅是网站。出于这个原因,我不得不将解决方案的构建分为两个步骤——首先只编译程序集(使用MSBuild任务),第二步调用AspNetCompiler编译网站


感谢您的帮助

如果您尝试直接在命令行上执行MsBuild,输出结果是什么:
MsBuild.exe BuildTest.sln/target:Build/p:Configuration=“Debug”,Platform=“AnyCPU”
?我已将命令输出添加到原始post中。这是相同的错误。对不起,我原来的post-HelpButton控件中有输入错误,它实际上位于web\controls\HelpButton.ascx中。抱歉搞混了,我已经编辑了我的问题来解决这个问题。嗯,好吧,对不起,我不能再帮你了。在最坏的情况下,您必须更改控件以使用代码隐藏文件并将属性放在那里。
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.235]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 9/9/2011 2:21:50 PM.
Project "d:\Src\MSBuildIssue\build.msbuild" on node 1 (default targets).
Project "d:\Src\MSBuildIssue\build.msbuild" (1) is building "d:\Src\MSBuildIssue\BuildTest.sln" (2) on node 1 (Build target(s)).
ValidateSolutionConfiguration:
  Building solution configuration "Release|Any CPU".
Project "d:\Src\MSBuildIssue\BuildTest.sln" (2) is building "d:\Src\MSBuildIssue\WebSite.metaproj" (3) on node 1 (default targets).
Build:
  C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -v /WebSite -p WebSite\ -u -f PrecompiledWeb\WebSite\ 
d:\Src\MSBuildIssue\WebSite\AnotherFolder\TestUserControl.ascx.cs(12): error CS1061: 'System.Web.UI.UserControl' does not contain a definition for 'HelpUrl' and no extension method 'HelpUrl' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?) [d:\Src\MSBuildIssue\WebSite.metaproj]
Done Building Project "d:\Src\MSBuildIssue\WebSite.metaproj" (default targets) -- FAILED.
Done Building Project "d:\Src\MSBuildIssue\BuildTest.sln" (Build target(s)) -- FAILED.
Done Building Project "d:\Src\MSBuildIssue\build.msbuild" (default targets) -- FAILED.

Build FAILED.

"d:\Src\MSBuildIssue\build.msbuild" (default target) (1) ->
"d:\Src\MSBuildIssue\BuildTest.sln" (Build target) (2) ->
"d:\Src\MSBuildIssue\WebSite.metaproj" (default target) (3) ->
(Build target) -> 
  d:\Src\MSBuildIssue\WebSite\AnotherFolder\TestUserControl.ascx.cs(12): error CS1061: 'System.Web.UI.UserControl' does not contain a definition for 'HelpUrl' and no extension method 'HelpUrl' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?) [d:\Src\MSBuildIssue\WebSite.metaproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.66
c:\Tmp\MSBuildIssue>msbuild.exe BuildTest.sln /target:Build /p:Configuration="Debug",Platform="Any CPU" 


Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.235]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 9/12/2011 12:05:38 PM.
Project "c:\Tmp\MSBuildIssue\BuildTest.sln" on node 1 (Build target(s)).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|Any CPU".
Project "c:\Tmp\MSBuildIssue\BuildTest.sln" (1) is building "c:\Tmp\MSBuildIssue\WebSite.metaproj" (2) on node 1 (default targets).
Build:
  C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -v /WebSite -p WebSite\ -u -f -d PrecompiledWeb\WebSite\ 
c:\Tmp\MSBuildIssue\WebSite\AnotherFolder\TestUserControl.ascx.cs(12): error CS1061: 'System.Web.UI.UserControl' does not contain a definition for 'HelpUrl' and no extension method 'HelpUrl' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?) [c:\Tmp\MSBuildIssue\WebSite.metaproj]
Done Building Project "c:\Tmp\MSBuildIssue\WebSite.metaproj" (default targets) -- FAILED.
Done Building Project "c:\Tmp\MSBuildIssue\BuildTest.sln" (Build target(s)) -- FAILED.

Build FAILED.

"c:\Tmp\MSBuildIssue\BuildTest.sln" (Build target) (1) ->
"c:\Tmp\MSBuildIssue\WebSite.metaproj" (default target) (2) ->
(Build target) -> 
  c:\Tmp\MSBuildIssue\WebSite\AnotherFolder\TestUserControl.ascx.cs(12): error CS1061: 'System.Web.UI.UserControl' does not contain a definition for 'HelpUrl' and no extension method 'HelpUrl' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?) [c:\Tmp\MSBuildIssue\WebSite.metaproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.77
<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"
        />
    </Target>