Search code examples
c#.netpowershellteamcityaspnet-compiler

/global.asax(1): error ASPPARSE: Could not load type


I have a .Net solution with a MVC website and an API project in it. The web project has <MvcBuildViews>true</MvcBuildViews>

and also

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'"> <AspNetCompiler Condition="'$(IsDesktopBuild)' != 'false'" VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" /> <AspNetCompiler Condition="'$(IsDesktopBuild)' == 'false'" VirtualPath="temp" PhysicalPath="$(PublishDir)\_PublishedWebsites\$(ProjectName)" /> </Target>

It precompiles fine when I invoke the commands locally via PowerShell. However, when the precompilation is triggered by the build server (TeamCity running under a service user), it fails with the below errors

/MyWebsite.Web/global.asax(1): error ASPPARSE: Could not load type 'MyWebsite.Web.MvcApplication'

/MyWebsite.Api/global.asax(1): error ASPPARSE: Could not load type 'MyWebsite.Api.WebApiApplication'

I have also tried invoking the precompilation command via PowerShell as myself and and as the service user on the build server and it works fine both times. It only seems to fail when the build gets triggered via TeamCity itself.

Here is the command I'm using to precompile the projects

aspnet_compiler -p "$path\$proj" -v $proj -fixednames -f -c -d "$precompiled_output_folder\$proj"

Any thoughts on what I may be missing here?


Solution

  • This issue was happening because the AspNetCompiler was looking for the types in the bin folder. The solution for me in this case was easy (getting there was not though). Just build the application before precompilation. This means that the dll that precompilation looks for will be in place.

    I still have a few questions unanswered like why does precompilation work for me locally without the dll and the bin folder. Also I still don't know why the precompilation works without the dll and the bin folder when I manually invoke the command as the service user on the build server.

    However, building before precompilation seems to do the trick for when the precompilation is invoked via TeamCity build steps.