MSBuild fails on temporary ASP.NET files - asp.net

I'm trying to set up Jenkins with MSBuild plugin. I got Jenkins to check out solution from repository and run a build. But every build fails with several
error CS0433: The type 'CustomControls_WarningPopup' exists in both (...)
WarningPopup is an .ascx defined twice - once per web site project, and there are two website projects in the solution. The thing is this never rises any problems when compiling whole solution from VS2010. Should I run MSBuild with some specific parameters to make it behaving like VS?
I already tried moving Temporary ASP.NET files to custom folder (like in this answer) and it didn't help. Probably I'm missing something obvious to CI experts here...

I found the cause. There was another UserControl in second project which accidentally inherited class of the same name. Both controls were in the same directory and nor Visual Studio during compilation nor ReSharper saw anything wrong with this. Moreover MSBuild threw errors in both Web Projects despite the duplicated control was in only one of them. The funniest part is that this situation was like this for months and never rised any problems...
Anyway changing class of this control solved the issue and finally automated build succeeded!

Related

Why does visual studio give me Type is not defined for my App_Code classes?

"Type 'HR.Database' is not defined'
I get that error for several classes that are stored in the App_Code folder in the Error List panel when building my project.
It is a class I wrote with namespace HR
How can I reference it or alter the project to recognize those classes and remove the error?
I thought I should reference it but when trying to add a reference there are no items in the list of projects. Also, they are .vb files and not a .dll
I wasted the better part of a working day on this problem before figuring it out...
When you add files to App_Code, Visual Studio sets the "Build Action" property to "Content", instead of "Compile" which it does for all other classes. So your classes don't get compiled, and then VS complains that it can't find them. Presumably this is VS' way of saying that App_Code is not where you should put your app code, reasonable as it may appear.
The solution is to right-click on each file and reset "build action" to "compile". This also has to be done whenever you add files. Or you could submit to VS and put your source somwhere else.
< /frustration>
Since it's late and over 3 years old. I came across a similar issue. The solution above is perfect.
With newer VS IDE versions, go to App_Code file's properties and update the Build Action to 'Compile' if it's set as 'Content'. Using App_Code folder may be outdated in newer VS versions but some older developers still use the folder.
Replace vbproj and vbproj.user with your backup
My issue wasn't the App_Code folder in particular, but I was getting "not defined" errors in my Errors List until I double-clicked to open the file, then references would resolve and that error would disappear without me doing anything more, but when I tried to rebuild, all these errors would appear again.
The only real clue I had was that they were all related to the same project and when I dug through my Output window, I could see there was a conflict on the .Net framework versions. Once I resolved the version difference, the errors disappeared.
I was getting this issue for a slightly silly reason, but it might help for others to learn from my pain. :D
I was making the changes to the code in a tab of my test program, but that tab was for a VB file in a DLL I was using. Since those changes weren't being made/compiled in the DLL, it wouldn't find the class no matter how hard I tried until I opened the DLL project, made the changes there and rebuilt the DLL.
I had the same issue in Visual Studio 2019 but the .vb file already had "Compile" in properties > build action
I had tried rebuild, clean, deleting the file.
If I copied an existing class into this folder it would also not be recognised
Closing visual studio and restarting it fixed the issue, so there's a bug in VS where it doesn't compile files in a new folder until VS is restarted

Error CS0433 in large precompiled Asp.net Website Project

Background
I've taken over a very large asp.net website project. The old deploy process was to copy .cs, .aspx, and .ascx files to IIS and have it build on the fly. I want to precompile it and use TeamCity to automatically deploy it. I've done this with some of the other website projects.
The project has about 350 user controls that are nicely organized in folders but are used all over the place. Controls referenced from other folders, from each other... Basically a circular file reference nightmare.
My Attempt
My first attempt was to build it like the others. MSbuild the whole vs2012 solution. I ran into tons of "circular file references are not allowed". Come to find out all these nicely organized controls are used everywhere and there are circular references are all over the place. I read this and I switched the "web.config" to compilation batch="false" and then in the build set the site to "not be updateable" and "use fixed naming assemblies". The site builds but takes literally 25 minutes to compile on my quad core, ssd, 16gb ram dev box. This is unacceptable build times.
I know that if I turn off "use fixed naming assemblies" that the site would build significantly faster. (I've proven it on one of the smaller websites. It went from 4 minutes to 45 seconds). When I do remove that setting I'm getting weird build errors:
c:\Projects\Web\Site.master(146): error CS0433: The type 'ASP.usercontrols_modules_viewprofilepopup_ascx' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_viewprofilepopup.ascx.4101713c.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_xa514so5.dll'
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_site.master.cdcab7d2.0.cs(927): error CS0433: The type 'ASP.usercontrols_modules_viewprofilepopup_ascx' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_viewprofilepopup.ascx.4101713c.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_xa514so5.dll'
error ASPPARSE: c:\Projects\web\Web\UserControls\Modules\JobsLeftMenu.ascx(128): error CS0433: The type 'ASP.usercontrols_modules_imagesgallerymodule_ascx' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_imagesgallerymodule.ascx.4101713c.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_nvrj33tx.dll'
error ASPPARSE: c:\Projects\web\Web\Site.master(146): error CS0433: The type 'ASP.usercontrols_modules_viewprofilepopup_ascx' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_viewprofilepopup.ascx.4101713c.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\web\8d37b2c6\4c39f0a\App_Web_xa514so5.dll'
Here is the exact aspnet_compiler.exe command:
aspnet_compiler.exe -v /web -p Web\ -f "Precompiled Web"
I googled around for answers. NO, they aren't duplicated in the code anywhere. They just happen to be in different folders, used by other controls in different folders. I have a feeling this is due to the circular file reference thing. Ok... Fine. I removed the usage of a few of these to see if it would build and the build process just moves onto other errors just like this one. I can't just remove code all over to accommodate this... How can I fix these errors without turning on "use fixed naming assembilies"?
Thing's I've Tried
Cleared the Temporary ASP.NET Files all throughout my system.
Tried a "publish" right from within visual studio 2012. Same errors.
Tried converting the site to a Web Application but got too many errors (upwards of 600+).
Again: made sure that there was no duplicate files and code that would explain it. I text searched the entire solution folder with notepad++ to validate that there wasn't another control with the same name.
Checked this.
I have msbuild performance tweaks turned on: /m /p:CreateHardLinksForCopyLocalIfPossible=true /p:BuildInParallel=true
I'm stumped and seem to think my only option is to rewrite the app, slog through the errors as I convert to a Web Application, or continue deploy source to the webserver but do it automated.
I known you've tried that already, but avoiding the circular references is going to be your best bet here. Note that the term 'circular reference' is actually not quite correct. What the build system complains about is circular references at the directory level, not the file level.
e.g. sub1\page.aspx uses sub2\uc1.ascx uses sub1\uc2.ascx
At the file level, there is no circle, but at the directory level there is, and that messed up with the way batching works.
While it may seem like you have so many of these situations as to make it unfixable, I'd bet that if you look at the details of the 'directory circles', it's down to not all that many. Drawing the reference graph might help make sense of things.
Then you just need to move the offenders into a different folder and change the links accordingly.
Yes, it's a painful process, but it is likely solvable.

Errors while compiling asp.net website

Hey guys,
i have a website, i want to place the compile code on the production server, now i took the code on the local machine and trying to compile source code on local machine, but whenever i compile the code, in one of my control(ascx.cs) file i am getting error that the control does not exists in current context, i checked everything, Inherits, CodeFile, even in the code behind(.cs) file, everything is perfect, even i get the control id in the intellisense, when i remove the control and again add the same using intellisense, the errors gets removed but after i publish site, the same error comes again....
Please reply with some suggestion/solutions.
I've had this issue before when referencing another project. It would give it intellisense, but then trying to compile would cause errors and take away intellisense. Removing and re-adding it would give me intellisense back.
The problem ended up being the target framework. The project was referencing .NET 4 Client Profile, whereas the project it was referencing was just .NET 4. Apparently this difference is subtle enough to trip up visual studio in the confusing way described above.
So take a look at your project's target framework, maybe you'll get lucky.
Definitely check your Inherits or CodeFile. I've had this happen before where I had them pointing at the wrong files.

System.MissingMethodException: Method not found

I have some user controls in the project kept under a folder UserControls.
I'm using one of the user control from that folder in my master page and one on Default.aspx. The default.aspx uses that master file.
The problem is that everything was working fine until something happened and it seems user control is not getting compiled. The user control calls a method from Business Logic which was parameterless before (when everything was working fine) but when I changed it to accept parameters and of course its calls too, it started giving the error. It is still searching for that parameterless method..!! :(
I did tried manually deleting the DLLs, deleting the user controls and again creating them. But nothing worked.
Anyone has any idea what I did wrong or what am I missing??
Try checking the build configuration manager (Visual Studio 2008 -> Build -> Build Configuration Manager). I ran into a similar issue and it turned out that one of the projects I was referencing was not marked to actually build (there is a check box that should be checked to build the assembly). Try changing the assembly version number of the assembly that is creating the issue, rebuild, then check that the version number of that assembly is correct.
I came across this problem and it was due to the fact an older version of my bin-deployed assembly existed in the GAC. Unfortunately there is no way to force DLLs to load from the bin directory if the GAC version has the same version number. See here: Dll in both the bin and the gac, which one gets used?

ASP.NET website does not rebuild

I have a solution with several projects in Visual 2008, let's say SuggestionProcessor (a class library) and Suggestions (a website) with a webhandler GetSuggestions.ashx. I changed a method in SuggestionProcessor which is used in the webhandler. The call in the webhandler has been adjusted to the changed method.
But now when I try to execute the webhandler after a rebuild I get an error that the method I changed is missing, displaying the old method signature. When I try to rebuild the entire project it seems that the website does not rebuild properly and the code I changed in the webhandler does not seem to be included in the rebuild. I made sure that the website is last in the build order.
What I tried is remove the dlls that the build process should rebuild from the bin folder (not the ones referenced from outside the website). When rebuilding I now get a: 'could not load type Suggestions.global'. Duh, that is what the build process should create. What is going wrong here?
I solved this one by reverting to a previous state when it still worked.
Thanks for the suggestions, I'm sorry they didn't work in my situation.
Shall I delete this question now that it doesn't really have a clear use for someone else?
I would check your web.config file, there may be references there that are causing the error since they are missing.
Maybe try and right click on your solution and select "Clean solution" and then try and rebuild all.
If that doesn't work, check your solutions build configuration and make sure all your projects are getting built
Try "Clean Solution", then building SuggestionProcessor, and after that clean and rebuild the web solution.
Visual Studio creates a copy of all your DLLs and sometimes this copies are not refreshed.
Just execute iisreset and delete all folders in:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary
ASP.NET Files\
Of course change windows installation folder and framework folder to your version!
I don't think so... I've seen similar issues in Visual Studio 2008 working on web projects where the build and rebuild would fail time after time. I knew that my changes shouldn't have affected the build so I just kept cleaning and building each of the individual projects in my solution until finally (and I do mean finally as in, it took up to 10 builds) my web project would build correctly. I have no idea why, but it feels like some sort of caching issue.
From my answer at "Could not load type [Namespace].Global" causing me grief:
It seems that VS 2008 does not always add the .asax(.cs) files correctly by default.
In this case, refreshing, rebuilding, removing and re-adding, etc. etc. will not fix the problem. Instead:
Check the Build Action of Global.asax.cs. It should be set to Compile.
In Solution Explorer, Right-click Global.asax.cs and go to Properties. In the Properties pane, set the Build Action (while not debugging).

Resources