Adding Sitecore 7.5 to existing solution - asp.net-mvc

I am trying to add the Sitecore as a separate project to an existing .Net MVC project which is built in .net framework 4.5.1.I followed the below steps to do so.
Copied Images,Assets,Scripts,Fonts folders from the existing Sample.Web project in to the sitecore project (now the sitecore project is the startup project instead of Sample.Web)
Added reference of Sample.Web to the sitecore project
Copied Views Folder as well because Sample.Web is using MVC
Merged Packages.Config file from Sample.Web Project to the packages .config that we get from Sitecore.
Merged the Web.Config file to the one present in sitecore project
I upgraded the sitecore project to target framework 4.5.1 as the existing projects were using Framework 4.5.1 using the extension https://visualstudiogallery.msdn.microsoft.com/47bded90-80d8-42af-bc35-4736fdd8cd13
Now in the above steps please suggest me on the below:
Will there be any issue in upgrading Sitecore Project to 4.5.1?
Solution is building successfully however I get the below run time error

My guess is your solution uses a more recent version of System.Web.Http than Sitecore does. Some Sitecore code is trying to load the older version of the DLL which you have most likely overwritten with the newer version, thus the exception.
If my guess is correct, I would suggest you rework your solution to use the same assemblies as Sitecore.

Related

AspNetZero - .NET Core 2.0 MVC Version - Error on adding new controller

After about 6 months, I returned to work on my AspNetZero solution based on .NET Core 2.0.
I have the original downloaded version and the modified version as separate GIT repositories. In both versions/repositories when I try to add a new MVC controller, I keep getting the below error message.
On my PC I have all of the .NET Core SDKs installed from 1.0 right up to 2.1.302. I have other projects that I am working on, where I'm using .NET Core 2.1.
I even created a brand new .NET Core 2.0 project in VS2017 and I am able to scaffold a new MVC controller without any errors. This issue is only happening on the AspNetZero solution.
I have done many searches for a solution and none of the answers I found online have worked. I just added a global.json file into my solution folder and set the SDK to 2.0.0 and tried again, still does not work. I keep getting the same error!
Your NuGet packages may have been invalid according to your
target framework. Check all your recent NuGet packages for .NET Core
versions.
Clear your NuGet cache as shown in the picture
Update: Delete all bin & obj folders.

How to migrate VS2010 MVC3 project to VS2015?

When I try to open an existing solution (to ultimately convert it to later MVC and .NET packages), VS2015 rejects the project:
The application which this project type is based on was not found. Please try this link for further information: http://go.microsoft.com/fwlink/?LinkID=299083&projecttype=E53F8FEA-EAE0-44A6-8774-FFD645390401
That link is worthless as it takes me to a VS2013 compatibility page.
My goal is to migrate the project from MVC3/.NET4.0 to MVC5/.NET4.5.
I can't target a later MVC or .NET in VS2010. VS2015 won't open the older project so the solution here won't work Some (official or not) upgrade Mvc3 to Mvc5 guide?? for changing the properties of the project since the project won't open.
Mvc3 is not supported after VS2010.Iuse VS2010SP1.
You may make it work but it will bite you in the end.
You have to choose the VS version and the corresponding Mvc version
I went into the csproj file manually and switched the ProjectTypeGuid to that of an MVC4 project: E3E379DF-F4C6-4180-9B81-6769533ABE47. Then VS2015 was able to open the project and it upgraded it to MVC5 guid correctly.

Missing reference to System.Web.Mvc in Asp.net Unit Test?

I recently made some unit tests for my Asp.NET MVC application, or I tried to, it keep telling me "The type 'System.Web.Mvc.Controller' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral.' Then I tried to add a reference to the above mentioned, but was only able to choose version 4.0.0.0 and now it tells me that my project already uses version 5.1.0.0, which is a higher version. What to do?
Thanks a bunch!
MVC 5 comes in from a NuGet package. Just as it did with the main MVC web project in your solution. Install MVC via NuGet into your Test project, and you should be good to go.
An educated guess, but you might have obtained the newer version via a nuget package(some of the newer MVC project templates do this), and thus it is not installed in GAC. Use the nuget package manager for the MVC project to determine if this is the case, and if so then mystery solved.
In the test project you can add the same package, or use the addreference->Browse to browse into the nuget dependencies and poke around under the MVC project till you find the DLL(it will be in the file system somewhere under SolutionName/MvcProjectName/packages).

MaxLength Attribute in EF4.3.1

The type 'System.ComponentModel.DataAnnotations.MaxLengthAttribute'
exists in both
[path...]\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll
and
'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework
\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'
Now, I have read on msdn that its safe to exclude the EntityFramework reference (which was added through the nuget package). However, when I do that, I cant create a DBContext properly as the DbModelBuilder class lives in the EntityFramework dll. Also, some other critical classes are missing when I remove the EntityFramework refference so this is old and irrelevant solution now.
Update (disambiguation): Both System.ComponentModel.DataAnnotations.dll and EntityFramework.dll include System.ComponentModel.DataAnnotations.MaxLengthAttribute. The problem is that each dll also includes other classes that are critical to EF code-first design. For example:
EntityFramework.dll:
- System.Data.Entity.DbModelBuilder
System.ComponentModel.DataAnnotations.dll:
- System.ComponentModel.DataAnnotations.RegularExpressionAttribute
Add this statement to top of your class
using System.ComponentModel.DataAnnotations;
System.ComponentModel.DataAnnotations namespace is distibuted across the EntityFramework.dll and System.ComponontModel.DataAnnotations.dll. So you need to add a reference to both of that in your project to make use of DataAnnotations.
The MaxLenth attribute is present in EntityFramework.dll. So make sure you have that reference to that dll present in your project references section.
EDIT : As of .NET framework 4.5, this namespace is moved to the System.ComponentModel.DataAnnotations.dll. So If you use .NET Framework 4.5 with Entity Framework 4.3.1 or less, You will run in to this conflict. The solution is to switch to Entity framework 1.50 beta 1/ 2 release if you want to stick with .NET 4.5 or downgrade to .NET 4 to use EntityFramework 4.3.1.
From the msdn documentations.
Starting with Entity Framework 5.0 Beta 1, the EntityFramework.dll
does not contain definitions for data annotations. These definitions
were moved to System.ComponentModel.DataAnnotations.dll and are
defined in the System.ComponentModel.DataAnnotations.Schema namespace.
I didn't have the option of upgrading the project to use EF5, or downgrading the build machine to .Net Framework 4.
There is a way to solve this though! It turns out when you install Visual Studio 2012 it adds the following folder (amongst others).
C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
In VS if you open a project targetting 4.0 and look at the properties of your reference to System.ComponentModel.DataAnnotations you'll see that the path is pointing to the above location, rather than the GAC.
This folder contains the original Framework 4.0 assemblies. If they're present on the machine then MSBuild etc., upon building a project targeting 4.0 will reference these rather than the modified ones that 4.5 puts into the GAC.
In our case this meant we could fix the problem by copying that folder from a dev machine with VS installed up to our build server in the same location. (N.b. We only needed to copy this folder, there was no need to install VS on the build server).
More info here: http://marcgravell.blogspot.co.uk/2012/09/iterator-blocks-missing-methods-and-net.html
Hope this helps someone else!

Installing a modified version of ASP.NET MVC

I have made a relatively simple change to the MVC 1.0 source code to correct a bug in the DropDownList HtmlHelper (discussed in another question).
I was able to rebuild the MVC solution, ran all the tests, including the one I hadd added to show the bug I was fixing, and built a new DLL.
But how do I use that?
I tried moving the new MVC dll into the project and changing all the project references to point to it, but when I try to run the MVC website, it's throwing an exception saying there's a conflict between my version of MVC and the MVC in the GAC.
I tried to use gacutil.exe to remove the one from the GAC, but it says it can't do that because it would make another program (the Microsoft Installer? fail.
What do I have to do to install my newly built version in place of the "official" version?
If you want to remove it from the GAC without uninstalling MVC (which includes the Visual Studio templates you probably need), you need to do this in the registry:
Find registry key HKEY_CLASSES_ROOT\Installer\Assemblies\Global and look for key starting with System.Web.Mvc – delete it
Now you should be able to use gacutil.exe to remove System.Web.Mvc from the GAC, and you should be able to use your version from your /bin folder.
How about changing the version number when you compile the modified MVC framework?

Resources