How to fix namespace issues after TFS check-ins? - asp.net-mvc

In setting up a solution for multiple developers, after checking in then checking out on another system, I consistently get the following error:
The type or namespace name 'OData' does not exist in the namespace
'System.Web.Http' (are you missing an assembly reference?)
Without checking in the bin folder, how can this be resolved on the working dev machine?

I found that the System.Web.Http.OData namespace is from Microsoft.AspNet.WebApi.OData which you can install from NuGet. So, to correct your current issue, right click the MVC project on that machine, select Manage NuGet Package, find Microsoft.AspNet.WebApi.OData to install it.

You can get visual studio to download the Nuget packages when you do a build locally, you can enable this through
Tools > NuGet Package Manager >Package Manager Settings
That way you're packages are not added to TFS and anything that your colleagues add to the solution will be automatically downloaded when you rebuild the code, when you first check out from source control

Related

Update Packages of a MVC Project

Im trying to use an ASP.NET web application downloaded from the internet. Im looking for a way restore all the dependencies/packages in a quick way (clean and building the project did not solve it), rather than installing them via nuget one by one. Is there anyway to download and install/resolve (version issues) all the necessary packages at once?
I tried below package manager console commands, but they did not resolve the package conflicts.
Update-Package -Reinstall,
nuget install packages.config and other solutions here - How do I get NuGet to install/update all the packages in the packages.config?
[resolve/install packages]
Can someone help? Maybe Im using wrong commands or doing something wrong.
If you go into Tools > Nuget Package Manager > Manage Nuget Packages for Solution, it will show a yellow bar at the top asking you if you want to restore missing packages. That's a manual way, but there are also some important VS options you want to look at as well, one being an option to restore packages on build.
There is a generic restore option as well from the package manager console, and that should have worked if it was simply a matter of reimporting the missing packages...
Update-Package -reinstall
You can try to delete the folders, than reinstall using these options. However, is there a possibility there is a .NET framework version mismatch with the version of the DLL's? Maybe some of the DLL's need updated?
Remove package folders from Package folder - don't remove package.config. Next, build you application - nuget should automatically restore all packages.

Build failure - Restore package option not working in Visual Studio Team Services (was VS Online)

I am using a TFS Git project in Team Services and while my project compiles locally, I get a build failure when I check in my code to VS online and manually queue the build.
The errors at the moment are only pertaining to enterprise library data access dlls. I am using V6 of the library and this is error I get
The type or namespace name 'Practices' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
In my build definition I have checked the box against both Restore Nuget Packages and when that alone did not work, I checked the box against [Clean] as well. I still get that error. My packages.config files are checked in for each of the projects in the solution. I also have the Packages folder checked in but this folder has no dlls. It only has the various .nupkg files and respective .xml files checked in. Is this causing the problem?
Yes, you have to either checkin the DLLs or delete the nupkg files. The build server thinks you already have the packages so its not trying to restore them but the DLLs aren't there to reference.

installing specflow for vs2013 mssing TechTalk.SpecFlow reference

I installed Specflow using the Download button
from the VS2013 specflow page
I added a feature to my Specs project using Add New Item and Choosing SpecFlow Feature File
When I build the project I get
Error 1 The type or namespace name 'TechTalk' could not be found (are you missing a using directive or an assembly reference?)
I also get an error mentioning that NUnit is missing.
Where would I find the files to reference and how do I check they are correct to go with TechTalk.Specflow 1.9.3.0 ?
Go to visual studio package manager console.
To install specflow for NUnit, type
Install-Package SpecFlow.NUnit
This will install all the required packages and a correctly configured app.config to work with NUnit.
If you instead resolved all the references by hand, then you would still have to construct the app config correctly. Finding the right config for MSTest or NUnit can take a little while to get right so it is better to just use the nuget package.

assembly uses System.Web.Http 5.1 which has a higher version than referenced assembly System.Web.Http 5.0

I created a new Project in Visual Studio 2013, a WebApi & MVC 5 project and updated all nuget packages. It updated to mvc 5.1. Now I cannot Successfully build the project it says
assembly uses System.Web.Http 5.1.0.0 which has a higher version than referenced assembly System.Web.Http 5.0.0.0
Anyone run into this before? Why these kind of problems do occur so often in Visual Studio? Does anybody know how to solve this because I really am trying hard but no luck so far...
Solved
I opened the Package Manager Console in Visual Studio and run the command
PM> Update-package
It magically resolved everything for me. You can find Package Manager Console under
Tools
Nuget Package Manager
Package Manager Console
This command deletes all the old packages under the package folder and updates everything if necessary, you may also run the command on a specific package. Here all the variants of the command http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference#Update-Package
Let me know if you found this useful I'm curious to know if it just happened to me accidentally
A new version of ASP.NET was released. Announcement here : http://blogs.msdn.com/b/webdev/archive/2014/01/20/announcing-the-release-of-asp-net-mvc-5-1-asp-net-web-api-2-1-and-asp-net-web-pages-3-1.aspx
You probably have two projects in your solution, where project A references project B. Both projects reference ASP.NET, but there is a version mismatch.
I had a very similar problem to yours exactly with a reference to System.Web.Http and have documented it here:
Could not load assembly error
When you update a Nuget package it would update dependent packages. But it would not update other packages in your solution that depend on the updated packages. These other packages might not even have a newer version built with the udpated packages.
So the solution is either to udpate all your packages like you did (this might not always work) or add binding redirects to the latest version of your assembly reference to your application config.
I solved this way. As I currently have fwk 4.0.0.0 and don't want to install 5.X:
I removed the referenced DLLs
I removed a couple of bindingRedirects at packages.config,
Then I rebuilded that solution, that throws me errors
Then I added the reference again
And voilĂ , the solution is running with the fwk that I have.

Referenced Dll's not found in Team Foundation Service (or: nuget packages not available on other pc)

when I create a build for the Team Foundation Service, I get all kind of reference dll's not found exceptions.
These references are added by nugget packages.
I've added the 'package restore' option on the solution which added 3 files in a .NuGet folder.
EDIT
When i got the solution from TFS on another pc, i got the same errors (missing dll's), so it's not only the TFS build service having problems.
The missing dll's are are missing files from installed nuget packages (some are part of the default VS template, Unity was a package i added later), which (the packages) are added on the first pc, but then are missing on the next pc (that's why i added the 'or' in the title of this question)
How can i get the Nuget added files on pc2 too?
I guess you've found a solution by now. I write this just to provide an answer for this question.
To have NuGet packages automatically downloaded on another PC, you need to enable NuGet package restore on build. You do this in two steps:
Right click the solution and select Enable NuGet Package Restore.
This will add a .nuget solution folder with NuGet.Config, NuGet.exe and NuGet.targets underneath it. These files should actually be checked in to source control, but the binary file is tiny. It will also modify the MSBuild scripts in all projects of the solution to import the NuGet.targets file to hook NuGet into the build process.
In Tools -> Library Package Manager -> Package Manager Settings make sure the option 'Allow NuGet to download missing packages during build' is checked.
This step must be done on all machines.
Now the BuildDependsOn property of all project build scripts should make the RestorePackages target in NuGet.targets kick in and download missing packages before you get build errors for missing references.

Resources