/global.asax(1): 错误 ASPPARSE: 无法加载类型

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

我有一个 .Net 解决方案,其中包含一个 MVC 网站和一个 API 项目。 Web 项目有 <MvcBuildViews>true</MvcBuildViews>

还有

<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>

当我通过 PowerShell 在本地调用命令时,预编译很好。但是,当构建服务器(服务用户下的 TeamCity 运行)触发预编译时,它会失败并出现以下错误

/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'

我还尝试以我自己和构建服务器上的服务用户身份通过​​ PowerShell 调用预编译命令,两次都运行良好。它似乎只有在通过 TeamCity 本身触发构建时才会失败。

这是我用来预编译项目的命令

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

关于我在这里可能遗漏的任何想法?

出现此问题是因为 AspNetCompiler 正在寻找 bin 文件夹中的类型。在这种情况下,对我来说解决方案很简单(虽然没有)。只需在预编译之前构建应用程序。这意味着预编译查找的 dll 将就位。

我还有一些问题没有得到解答,比如为什么在没有 dllbin 文件夹的情况下预编译在本地对我有效。另外,当我在构建服务器上以服务用户身份手动调用命令时,我仍然不知道为什么预编译在没有 dllbin 文件夹的情况下工作。

但是,在预编译之前构建似乎可以解决通过 TeamCity 构建步骤调用预编译的问题。