"type or namespace name ... could not be found" errors building .NET application

时间:2015-07-31 20:33:03

标签: .net build

I have web solution (MVC 5). Also in this this solution there are few console applications. I can buil entire solution locally without any errors. But on TC I can't build Web solution (but can all console apps and class libraries). I'm getting such error:

error CS0246: The type or namespace name 'HttpRequestMessage' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'HttpRequestMessage' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'AuthenticationHeaderValue' could not be found (are you missing a using directive or an assembly reference?)

Only these 3 entities can not be found in a different files. I can see referenced System.Net, System.Net.Http, System.ServiceModel.Channels assemblies. I'm sure (from build logs) they are referenced from 4.5 (all projects built with 4.5)

What is the problem in?

3 个答案:

答案 0 :(得分:1)

Is TeamCity downloading NuGet packages for you?

You may need to add the NuGet Installer build step to your configuration. Just point it at your .sln file and it should grab all the packages for you.

答案 1 :(得分:1)

The problem was in references. System.Http and System.Http.Net were not referenced properly. Solution - to remove references and add them back again

thanks

答案 2 :(得分:0)

Search your code for those types and figure out what assembly they're from. Then check the references for the Visual Studio project that contains that code. You can also examine the .csproj file directly. Look for references with a 'hint path' that aren't in the directory of your Visual Studio project/solution. If you're referencing a file that's not in your project's directory it's probably not in your project's version control repository either. So unless that assembly happens to exist somewhere on the server where TeamCity is running – and the directory in which that assembly file resides is also on the system path for the user that the TeamCity server is running under, TeamCity won't be able to find that file when it attempts to run your build tasks.