MSBuild fails, but building inside Visual Studio works fine
- by Matt
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.