2011-09-12 6 views
4

Webサイトプロジェクトを含むVS2010ソリューションを構築するときにMSBuildタスクを使用しようとすると、異常な動作が発生します。 Visual Studio 2010でそのソリューションを開き、コンパイルしようとすると機能します。しかし、MSBuildスクリプトからコンパイルしようとすると、エラーが発生して失敗します。MSBuildでWebサイトのコンパイルが失敗しますが、Visual Studioで動作します

WebSiteディレクトリにUser Controlがあり、コードの背後にはありません。

再現手順:

1.簡単な解決策があるとします。ただ、ウェブサイトと2つのユーザーコントロールを持つ:

ウェブ\コントロールHelpButton.ascxを\:

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

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

</script> 

ウェブ\ AnotherFolder \ TestUserControl.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestUserControl.ascx.cs" Inherits="AnotherFolder_TestUserControl" %> 
<%@ Register Src="~/Controls/HelpButton.ascx" TagPrefix="myCtrl" TagName="HelpButton" %> 

<myCtrl:HelpButton runat="server" ID="HelpButton" /> 

ウェブ\ AnotherFolder \ TestUserControl。 ascx.cs:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class AnotherFolder_TestUserControl : System.Web.UI.UserControl 
{ 
    protected override void OnLoad(EventArgs e) 
    { 
     this.HelpButton.HelpUrl = "trada"; 

     base.OnLoad(e); 
    } 

} 

VS2010はこのウェブサイトを問題なく構築できます。 MSBuildの次

2)用途:それは私には見えます

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 

:次のエラーが表示され

MSBuildのbuild.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> 

3.

)MSBuildのスクリプトを実行します。ユーザーコントロールが間違った順序でコンパイルされたように 'HelpButton'は 'TestUserControl'に配置され、 'TestUserControl'は 'HelpButton'オブジェクトのプロパティに値を割り当てます。 これは既知の問題ですか?これを回避する方法はありますか?

MSBuildスクリプトからdevenv.exeを実行し、devenv.exeでソリューションをビルドすることでした。それは正常にコンパイルされますが、問題は、この方法で追加のMSBuildプロパティを送信できないことです。

はありがとう

編集:ソリューションファイルに対して直接実行MSBuildのコマンドの出力:これは何行<%@ Register Src="~/Controls/HelpButton.ascx" ...について

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 
+0

ため

感謝の設定=「デバッグ」を、プラットフォーム=「AnyCPU」 '? – Andreas

+0

元の投稿にコマンド出力を追加しました。それは同じエラーです。 –

答えて

0

?あなたのボタンは別のディレクトリにあるようです。

+0

申し訳ありませんが、私の元の投稿にタイプミスがありました - ヘルプボタンコントロールは実際にはweb \ Controls \ HelpButton.ascxにあります。混乱のために申し訳ありません、私はそれを修正するために私の質問を編集しました。 –

+0

申し訳ありませんが、私はあなたをさらに助けることはできません。最悪の場合、コントロールを変更してコードビハインドファイルを使用し、そこにプロパティを配置する必要があります。 – Andreas

1

最後にMSBuildの代わりにAspNetCompilerタスクを使用しています。意外にも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> 

私は私たちの本当の生産ソリューションで解決しなければならなかった唯一の問題だった、私たちのソリューションは、他の多くのプロジェクト(アセンブリ、実行ファイル)だけでなく、ウェブサイトが含まれていること。そのため、私はソリューションのビルドを2つのステップに分割しなければなりませんでした。最初はMSBuildタスクを使用してアセンブリをコンパイルし、2番目のステップではAspNetCompilerを呼び出してWebサイトをコンパイルしました。 `のMSBuild.exe BuildTest.sln /対象::/ Pのビルド:あなたは直接コマンドラインでのMSBuildを実行しようとした場合、出力は何の助け

+0

が動作します。ありがとう。 – Birey

関連する問題