Showing posts with label NuGet. Show all posts
Showing posts with label NuGet. Show all posts

Wednesday, April 11, 2012

Get Started Using NuGet on Visual Studio 2010

You’ve been hearing things about NuGet, but aren’t sure where it is our how to use it. This is a basic instruction on how to get started.

Why NuGet? Developer Productivity. It makes it easier to do things like add Asp.Net Ajax or other libraries and utilities to your project without constantly searching the web for the download and installation process. It is great for items you add to your solutions regularly, but don’t always remember the steps because it has been a while since the last time.

NuGet

  1. Go to NuGet.org to download and install NuGet, a Visual Studio extension that makes it easier to download and install third party libraries in a Visual Studio project.
  2. Restart Visual Studio, if you had it open.
  3. Open the project you want to add the utility or library to.
  4. Click “Manage NuGet Packages” under the Visual Studio 2010 “Project” menu. image
  5. Search for a utility you are interested in, such as “AjaxControlToolkit”, “Modernizr”, or “MvcScaffolding”.
  6. Click the “Install” button.

Friday, July 15, 2011

Error using MvcScaffolding with EF4.0

scaffoldingIf you are just starting out with the MvcScaffolding Nuget package to scaffold your basic CRUD operations on an MVC3 project, you should know that it requires EF 4.1 to run correctly without the following error.

The type 'LPM.Project' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject

If you already ran the scaffolding via the Package Manager Console using syntax similar to the following, PM>scaffold controller <table> –Repository –Force, to resolve the error, I needed to:

  1. Delete the scaffolded controller files and view files from the project.
  2. Install the Entity Framework 4.1
  3. Re-Generate the Database From Model (assuming that is how you created the Entities to begin with)
  4. Right click on the .edmx Design surface, click Add Code Generation Item.
  5. Click the Code link in the Installed Templates tree. Select ADO.Net DbContext Generator. Name the code generation template, it ends with a .tt extension.
  6. Rebuild the project.
  7. Re-scaffold the tables.
  8. Run the project

Steps 4 & 5 above were the key to getting it to work after installing the Entity Framework 4.1 and with all my combinations of re-scaffolding, re-generating the model, re-creating the model, etc. That important bit of information came from MVC 3 Scaffolding issue with Entity Framework.

If you look at the Model.designer.cs (or .vb) code prior to adding the ADO.Net DbContext Generator, you will see that the Model entities do inherit from the EntityObject (which is noted in the error message as a potential cause of the exception). Adding the ADO.Net DbContext Generator disables the default code generation and inherits from the DbContext instead.

more information: