TeamCity won't build with NUnit class library - asp.net

I have a .NET solution set up that has the main ASP MVC project and then a class library project that has had NUnit added to it for unit tests.
When I build the solution in TeamCity the main project builds fine but then when the test project builds I get these errors
error BC30002: Type 'TestFixture' is not defined.
error BC30002: Type 'Test' is not defined.
error BC30389: 'System.Diagnostics.Assert' is not accessible in this context because it is 'Friend'.
I assume it can't find the NUnit.dll or something but the dll is in the solution packages folder. I've tried doing package restore first in case it was that but it still did the same.
Update
Ok, just to test it I added Moq to the project to see if it would pick up the references. It did and worked fine, it seems to be only problem when I try to use NUnit functions. I could disable it from building but surely the NUnit tests won't be picked up in Team City?
Thanks!

Finally fixed the issue and it was my own stupid mistake. Thanks to DevOps for suggesting going through the MSBuild logs, it helped my track down the problem.
The actual DLL wasn't getting checked in to source control because the dev machine that added the test project had a global ignore file to ignore all DLL's. So I thought it was there but it was just the .xml file and I mis read it.
Anyway it now builds and runs the tests.
Thanks for the help everyone

Related

Xunit test not copying appsettings file to output directory

I have a Xunit test project that targets both .NET Core 3.1 and .NET Framework 4.6.1. My test loads an appsettings.json file as detailed by Rick Strahl. When the test runs, even though I have set the file properties to be of Content type and to always copy to output directory, the file isn't actually there when the test runs.
Now I was successfully able to use this technique in another unit test project, but the difference is that one targets .NET Core 3.1 only. In the working test project, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) is C:\git\myproject\src\myproject.tests\bin\Debug\netcoreapp3.1 (i.e., the build output directory). However, in the failing test, the location is C:\Users\hcheng\AppData\Local\Temp\ffe98278-56d3-41f6-8864-e50c74cb2c08\ffe98278-56d3-41f6-8864-e50c74cb2c08\assembly\dl3\8ba8de87\6b2a96ca_54b8d601 and when I open Windows Explorer to that path, the only contents in that folder are the DLL and the PDB of the unit test project, and __AssemblyInfo__.ini (none of the other dependencies are there either).
I'm totally new to .NET Core so I can't really tell what I'm doing wrong, but I suspect that the multi-targeting is related. Since the other dependencies are missing from that temp location, I'm also worried that if I get past this hurdle of loading the config file, I'll still get TypeLoadExceptions afterwards.
Thanks in advance for your help.
I eventually found the answer in How to refer to test files from Xunit tests in Visual Studio?.
Instead of Assembly.GetExecutingAssembly().Location, I had to use new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath.

problems setting up aspnetcore-angular2-universal example seed

We are for some time now trying to find a solution for server prerendering of SPA, specifically Angular4, for the purpose of SEO.
We have come to try and use aspnetcore-angular2-universal, which seems to be the perfect solution, however, we encounter problems deploying the published build to a local IIS server.
We have posted an issue regarding the problem on the issues page at which can be found here:
https://github.com/MarkPieszak/aspnetcore-angular2-universal/issues/491
We have followed the instruction under "Getting started" & "Deploy" (which can be found here: https://github.com/MarkPieszak/aspnetcore-angular2-universal) exactly but the error still exist.
The support is unresponsive on issues and thus we are posting also here.
The problem is (as mention in the issue linked here) that we get the following error:
Which indicates a problem with the web.config file. However the webconfig file is exactly as supplied in the starter project and seems also legit.
I should mention that building and running the project using npm build:prod and dotnet run works and we can lunch an in memory application from Visual Studio Code, however when taking the published folder to an IIS folder the error occurs.
Any help will be appreciated.
Did you installed .NET Core Windows Server Hosting bundle?
Check if AspNetCoreModule listed in IIS => Modules. Sometimes it not installed properly during #1, even if there was "Succeeded" at all steps. In that case I just removing it via Program & Features, and reinstalling it then.
Once I saw that error when manually copied web.config from sources over the publish folder. Problem is that original web.config contains placeholders like %LAUNCHER_PATH% and %LAUNCHER_ARGS%, which turns to appropriate values (dotnet and .\YourApp.dll for instance) during dotnet publish
Aperantly there were incompebilities between angular5 & universal in serverside.
The https://github.com/MarkPieszak/aspnetcore-angular2-universal seed was downgraded to using angular4.3 instead of 5. When we updated seed, the problem was solved.

MSBuild fails on temporary ASP.NET files

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!

TeamCity compilation failure because of excluded files

I have a VS2010 solution with web-site project.
It has some excluded files.
When I build the solution with TeamCity,
compilation fails because it misses some files which are excluded.
TeamCity error:
/BT.Account.csproj/Controls/Panels/TogglePanel.ascx(1, 0): error
ASPPARSE: Could not load type
'BT.Account.Controls.Panels.TogglePanel'.
Do a fresh checkout to a new local directory and try to build that. Any error arising in TeamCity should be present in the new checkout. There you can see what really happens. My guess is that the .ascx file is still included in the project.
It depends what your TeamCity does when it runs a build.
If it runs an aspnet_compiler.exe job then you might get this error if your ASPX markup (not the codebehind) has an error in it. I've seen this many times in some of my own TC projects :)
Normally ASPX markup errors are basically ignored until the page is visited (then resulting in a YSOD), but when you do an ASP.Net compile (or a publish) the markup will be compiled down into a DLL in the bin folder. Hence any mistakes will cause a compilation error and make the build fail, with an error similar to yours.
If that's the case, have a look at TogglePanel.ascx and see if there are any errors.
If not, I hope you are able to solve the problem quickly and easily. Good luck :)

Could not load type MyNameSpace.PageName

I have switched to a new PC and got the latest version out of source safe but now when I do a ReBuild I get Could not load type then the name of my namespace.the name of my pages?
It seems ok if I do a Build.
Any ideas?
UPDATE: Once a Rebuild is done it removes the Namespace.dll and then doing a Build it fails with the same errors.
UPDATE 2: I think it has something to do with aspnet_compiler.exe? Do standard Web Applications run this after a build? I have setup another test Web Application and it runs Csc.exe but not aspnet_compiler.exe but I can't see anywhere in my project where its configured to run this.
maybe you have refferenced a DLL directly, instead of a project in a solution.
This could cause a rebuild to work
I've lost references before when I've moved to a new machine. So, I would start by checking the references on the projects with the errors.
I found in my csproj file the following:
<AspNetCompiler PhysicalPath="C:\Projects\MyProject" Debug="false" VirtualPath="/MyProject" />
Not sure what this is doing, I think it was put in there for some reason.

Resources