20

I just upgraded my project to Asp.Net 4, from 3.5. When the build kicks off from TeamCity, I get the following error:

[Project "Website.metaproj" (Rebuild target(s)):] C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /Website -p Website\ -u -f PrecompiledWeb\Website\
[12:11:50]: [Project "Website.metaproj" (Rebuild target(s)):] ASPNETCOMPILER error ASPCONFIG: Could not load file or assembly 'Microsoft.VisualBasic.Activities.Compiler' or one of its dependencies. An attempt was made to load a program with an incorrect format.
[12:11:50]: MSBuild output:
[12:11:50]: Copying file from "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\Dependencies\wnvxls.dll" to "Website\\Bin\wnvxls.dll".
[12:11:50]: Copying file from "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\Dependencies\wnvxls.xml" to "Website\\Bin\wnvxls.xml".
[12:11:50]: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /Website -p Website\ -u -f PrecompiledWeb\Website\
[12:11:50]: ASPNETCOMPILER : error ASPCONFIG: Could not load file or assembly 'Microsoft.VisualBasic.Activities.Compiler' or one of its dependencies. An attempt was made to load a program with an incorrect format. [C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\Website.metaproj]
[12:11:50]: Done Building Project "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\Website.metaproj" (Rebuild target(s)) -- FAILED.
[12:11:50]: Done Building Project "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\MyProject.sln" (Rebuild target(s)) -- FAILED.
[12:11:50]: Done Building Project "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\MyProject.sln.teamcity.patch.tcprojx" (TeamCity_Generated_Build;TeamCity_Generated_NUnitTests target(s)) -- FAILED.
[12:11:50]: Build FAILED.
[12:11:50]: "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\MyProject.sln.teamcity.patch.tcprojx" (TeamCity_Generated_Build;TeamCity_Generated_NUnitTests target) (1) ->
[12:11:50]: "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\MyProject.sln" (Rebuild target) (2) ->
[12:11:50]: "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\Website.metaproj" (Rebuild target) (3) ->
[12:11:50]: "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\MyProject.Other\MyProject.Other.csproj" (Rebuild target) (5) ->
[12:11:50]: (CoreCompile target) ->
[12:11:50]: Helpers\ProgramHelper.cs(40,21): warning CS0168: The variable 'ex' is declared but never used [C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\MyProject.Other\MyProject.Other.csproj]
[12:11:50]: "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\MyProject.sln.teamcity.patch.tcprojx" (TeamCity_Generated_Build;TeamCity_Generated_NUnitTests target) (1) ->
[12:11:50]: "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\MyProject.sln" (Rebuild target) (2) ->
[12:11:50]: "C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\Website.metaproj" (Rebuild target) (3) ->
[12:11:50]: (Rebuild target) ->
[12:11:50]: ASPNETCOMPILER : error ASPCONFIG: Could not load file or assembly 'Microsoft.VisualBasic.Activities.Compiler' or one of its dependencies. An attempt was made to load a program with an incorrect format. [C:\Program Files\TeamCity\buildAgent\work\8bbb8fc03bd91944\Website.metaproj]
[12:11:50]: 1 Warning(s)
[12:11:50]: 1 Error(s)
[12:11:50]: Time Elapsed 00:00:31.48

I tried copying the .net framework reference assemblies to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0 thinking that would fix things, but still no luck. Any thoughts?

Jim Geurts
  • 20,189
  • 23
  • 95
  • 116
  • I found this fixed it for me: http://www.itsupportforum.net/topic/the-imported-project-microsoft-webapplication-targets-was-not-found-msbuild/ Summary: Wrong version of msbuild and .net – Boris Nov 02 '17 at 01:34

9 Answers9

11

For me it was indeed an x86/x64 mismatch. I solved it by specifying the path to the x64 MSBuild through the MSBuild environment variable:

Set the MSBuild environment variable

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
9

This error had to do with class libraries in the solution referencing older (v3 or v3.5) system assemblies. Those class libraries were referenced by my website, so the system assemblies got copied to the bin folder along with the class libraries. Maybe the system assemblies in the 3.5 directory have different permissions than the 4.0 directory and when the aspnet_compiler tried to load them from the bin directory, it barfed.

After going through each csproj file and updating <RequiredTargetFramework> values to 4.0, everything is working as expected.

Jim Geurts
  • 20,189
  • 23
  • 95
  • 116
7

I got the same error building the .csproj_deploy from VS. All other projects including the web in the solution built fine. There was actually this Microsoft.VisualBasic.Activities.Compiler dll in my web bin folder. When I clicked build/clean solution, all the files in the folder got deleted except this. I manually deleted this file and built again and it built fine. This time, I do not even see this file in the bin folder.

T.S.
  • 18,195
  • 11
  • 58
  • 78
sri
  • 71
  • 1
  • 2
  • Apparently, regardless from running a Clean Build action, these files indeed remain in the build folder and wreak havoc on your build process. We could clear the problem only after we removed references to other VisualBasic libraries in the projects, and _then_ clearing the build's bin-directory. – Abel Dec 09 '10 at 15:17
2

I found the very simple accepted solution presented here fixed the issue for me, this being installing the Windows SDK for .NET Framework 4 (or the equivalent for your Windows version).

Note the comment on the accepted answer that says "Intellisense and Reference Assemblies" are the only features from the SDK needed to fix this issue.

Community
  • 1
  • 1
Holf
  • 5,605
  • 3
  • 42
  • 63
2

The simple solution that worked for me was to modify the TargetFrameworkVersion line of the .vbproj file. Simply changing "v4.0" to "4.0" removed all of the copmiler errors and fixed my intellisense issues (asp.net tags were not being recognized).

Jason
  • 21
  • 1
2

We had this error when switching our hosting environments (to the new web server with IIS).

The fix was:

  • Either change the Application pool / Advanced settings, and set Enable 32 bit applications to true, or
  • Delete all assemblies from the bin folder that already belong to the framework (e.g. we had System.Data.dll in our bin folder, which was obviously built for 32b - deleting it fixed the issue)
veljkoz
  • 8,384
  • 8
  • 55
  • 91
2

Looks like an x86/x64 mismatch - I'd strongly recommend actually using the framework installer, than hacking it by copying the files by hand

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
  • @Rowland I did install the framework. I wasn't able to find an install for .net framework 4 sdk, which is why I copied the files manually. I'll try installing the sdk if you can provide a link :) – Jim Geurts Jun 16 '10 at 17:31
  • @Jim I assume you tried: http://msdn.microsoft.com/en-us/netframework/aa569263.aspx Although it looks from the error that it's looking for parts of the Visual Studio SDK (from: http://msdn.microsoft.com/en-us/library/bb166441.aspx ) – Rowland Shaw Jun 16 '10 at 17:56
  • @Rowland Yep, I originally installed the .net framework 4. I uninstalled it and am reinstalling it, in hopes that it fixes things. I don't believe the VS SDK will help me here. My project isn't related to VS - I'm not referencing it or extending it – Jim Geurts Jun 16 '10 at 18:02
  • @Rowland Unfortunately, reinstalling the framework did not fix things. Any other thoughts? btw, I downloaded the framework from: http://www.microsoft.com/downloads/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&displaylang=en – Jim Geurts Jun 16 '10 at 18:10
  • Have you checked to ensure that the application pool your app is running in, is running the correct framework? You could use depends or filemon to try and identify which dependency/dll is failing... – Rowland Shaw Jun 16 '10 at 18:36
  • @Rowland This looks to be a bug with TeamCity. When I run the command manually and use the aspnet_compiler from the Framework64 directory, things work as expected. Thanks for your help – Jim Geurts Jun 16 '10 at 19:04
  • Sounds more and more like an x64/x86 issue. Unfortunately I have minimal knowledge of Team city, so will have to bow out – Rowland Shaw Jun 16 '10 at 19:11
  • @Jim Geurts... you're comments here are uncannily similar to my experiences today, right down to suspecting a TeamCity bug. Installing the Windows SDK for .NET Framework 4 fixed it for me. – Holf Jul 12 '12 at 14:26
0

I found that I had an unnecessary reference to the 'Microsoft.VisualBasic.Activities.Compiler' dll. Once I removed the reference, all things worked.

OJisBad
  • 367
  • 4
  • 9
0

If you are building a web project in x64 in Visual Studio and running on IIS Express you must enable the following setting:

Tools --> Options --> Projects & Solutions --> Web Projects --> Use the 64 bit version of IIS Express for web sites and projects

Michael Armitage
  • 1,502
  • 19
  • 17