MSBuild fails, but building inside Visual Studio works fine

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2009-05-19T22:27:32Z Indexed on 2010/05/08 0:28 UTC
Read the original article Hit count: 556

Filed under:
|
|

C#, .NET 2.0

I have an ASP.NET website in a solution, with 2 other projects (used as library references). When I build (debug or release) in Visual Studio, everything works fine. However, building with MSBuild fails.

This build had been working (it's actually invoked via a nAnt task). The only thing that has changed is that I have a new user control whose Type I am referencing in my code behind.

The offending code is in my ASPX code behind. MessageAlert is the UserControl:

MessageAlert userControl = this.LoadControl("~/UserControls/MessageAlert.ascx") as MessageAlert;
        userControl.UserMessage = message;
        this.UserMessages.Controls.Add(userControl);

In order to get Visual Studio to recognize the type 'MessageAlert' I had to:

1) Set the ClassName="MessageAlert" in the @Control markup at the top of the user control (because using the auto-generated UserControls_MessageAlert wasn't working either)

2) Register the user control in the markup of my ASPX, using an @Register

3) Add a "using ASP" to the top of my code behind

After those steps, I could successfully reference the MessageAlert type in my codebehind from visual studio. But from MSBuild I get "The type or namespace name 'MessageAlert' could not be found (are you missing a using directive or an assembly reference?) "

The MSBuild execution is very simple - it points the the very same solution file and sets the configuration property to release.

It seems, based on the # of steps I had to go through to get Type references to MessageAlert in Visual Studio, that there is something missing in the MSBuild process. But what? Doesn't Visual Studio in fact invoke MSBuild behind the scenes?

Is there a better way to reference a UserControl type in the code behind of an ASPX?

EDIT: To clarify, the MessageAlert user control is not in the other referenced assemblies/projects. I mentioned them because, together with the website, the compose the Solution file, which is the same sln file being built by MS Build.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about msbuild