I am trying to set up an ASP.NET MVC 5 project in Visual Studio 2013, based on another project I have been given by somebody significantly more experienced than me. In his project, there is a References folder, with references to System, System.Core etc., together with third-party libraries. However, this folder does not exist by default in my new ASP.NET MVC 5 project. Instead, I have a folder called bin, which looks similar to References, and I can add references to dlls. What is the difference between the References and bin folders? Why does his project have one, and mine has the other? Thanks.
Your references 'folder' are assemblies (DLLs) that are referenced by your project. The reference is held in text in the project file.
The bin folder is used for compilation of your project. At compile time, the references in the project file are resolved (located for use by your project when it's running). This may be copying them from another location on disk, downloading a nuget package or using a version from the GAC. If the assembly is going to be copied down from another location it will be copied into the bin folder where all the files necessary for the application to run are stored.
UPDATE:
A different project type had been added and hence the references folder was not visible. Adding an ASP.NET Web Project into the solution solved this.
In Visual Studio 2015:
File >> New >> Project (Web Application)
A Project will have a References node when viewed through Solution Explorer in the IDE. If viewed with a file explorer (Windows Explorer) there is no Reference folder. References are stored in the project (csproj or vbproj) file using plain xml/text.
File >> New >> Web Site
A Web site does not have the References node nor a project file. In Solution Explorer right-click on the Bin folder or the root node to add References. References can be seen in the Property Pages (right-click root node).
Related
I recently inherited some source code developed by someone else who is no longer with the company. However, the solution file was missing and I'm not even sure which version of MVC it was using. I'm experienced with ASP.NET, but not well-versed in MVC so I'm unsure how to go about rebuilding the solution the proper way. Looking for any tips/guidance on how to go about this.
Create a new, blank solution.
Open the solution in Windows Explorer.
Copy the project files into the solution folder.
Within Visual Studio, right-click the solution in Solution Explorer, and then chose the option to Add Existing Project....
Navigate to the solution folder (if necessary), and then select the .csproj (or .vbproj) file. The project will added into the solution.
Now, whether you can compile the solution/project depends on whether the version of MVC is compatible with the tooling installed in your instance of Visual Studio. If the project has NuGet dependencies, they should be restored the first time you build, depending (again) on your version of Visual Studio and tooling.
Edited:
Since you say that even the project file is missing, you can, assuming there are no external dependencies, create a new MVC project and then copy/paste the files into it (or drag & drop the files from Windows Explorer). Assuming there is a Views folder, it will have it's own web.config file. That config file will have bindings for the version of MVC the project was developed with.
MVC4 and newer projects tended to default to using Razor syntax, so the views will be littered with stuff like #Model. If it's using the older WebForms syntax (like <asp:ContentPlaceholder>), it's probably MVC3 or older.
Go to web.config file in the project and look for:
assembly="System.Web.Mvc,Version=3.0.0.0 ..."
In this example is.MVC 3, look for your version
Is it possible to import an already existing Umbraco site into Visual Studio? (By means of getting all the site files and DB backup)
I've tried creating an empty project and copying the website files, but I get several errors when I try to compile the solution. The errors look like "Could not find scheme information for the element 'umbracoConfiguration'."
The same happens if I create an empty solution, add the UMBRACO nuget package, and then copy the website files.
I'm wondering if it is at all possible, or if once an UMBRACO website is running, how should one customize/develop on it?
THANK YOU!
After several attempts and trial and error, as well as reading other blogs, the way it worked for me was to go in Visual Studio -> File -> Open -> Web Site... and select the main folder containing all the files.
It is important to know that the web.config had to be modified in advanced for the website to work to point to the local server and off course attach the DB to the local SQL server.
Everything works perfectly just the way it was working on the host, and I have the solution in Visual Studio.
I like to start with nuget because it handles setting up all of my project references. I create a new MVC4 Web Application
Visual Studio->File->New->Project->MVC4 Web Application
After I create the new application, I open the Nuget Package Manager Console
Tools->NuGet Package Manager->Package Manager Console
I then enter the command:
Install-Package UmbracoCms.Core -Version 7.2.1
I find that installing the UmbracoCms.Core instead of the whole UmbracoCms nuget package is best because it only sets me up with the umbraco dlls and sets up the references for me. The UmbracoCms nuget package tries to do a lot more and is more handy if you are setting up a brand new umbraco site in Visual Studio.
Once I have nugetted the appropriate version of umbraco, I copy my existing umbraco site files over the files that were nugetted. When you copy all of the files over, don't copy all of the App_Data. Most of the files in that directory are TEMP files and cache files. From App_Data, only copy the following. This will save you time reindexing the site. I suspect a lot of the App_Data files were responsible for your Object Null Reference.
App_Data/access.config
App_Data/packages/*
In visual studio, in the solution explorer, click "Show All Files", and then include the appropriate files in the solution. Rebuild the solution, and you should be set up for development.
I'm trying to publish a solution that contains several projects -one of them is MVC- to IIS7.
When the MVC project is published and some views are being accessed I get the following error:
Could not load file or assembly 'NHibernate.Mapping.Attributes, Version=3.2.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The system cannot find the file specified.
This happens because the view I'm trying to access is calling a function in another project in that solution and needs this library!
but this library is not contained in the MVC project!
I was able to solve it by referencing that DLL in the MVC project! but I need another solution, because it doesn't make sense to reference every single DLL in all the other projects!
I'm using the "Web Deploy" publish option for the MVC project, is there another way that I can publish it and make it work without referencing all the DLLs from all the other projects?
There is an article on how to deploy assemblies that are not referenced by your MVC project directly:
http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx
Basically you need to create a folder in your project called _bin_deployableAssemblies and add your assemblies to it. They will get deployed with the website.
Here is a quote from the article:
So here’s the kicker. If you’re building a web application, and you
need an assembly deployed but don’t want it referenced and don’t want
it checked into the bin directory, you can simply add this folder
yourself and put your own assemblies in here.
I have a solution with 2 projects:
Project 1: Wrapper.Dll which contains a NLog wrapper. NLog and NLog.Extended have been installed with Nuget.
Project 2: is an ASP.Net MVC project which contains a reference to project 1.
When I try to run the web project, it throws an exception because NLog tries to load a target renderer from NLog.Extended.Dll.
If I check the bin directory of Wrapper.dll, I have NLog.Dll and NLog.Extended.Dll.
If I check the bin directory of the Web project, I only have NLog.dll.
How can I tell Visual Studio to copy the NLog.Extended.Dll from project 1 to project 2?
EDIT: Adding some dead code that use something from NLog.Extended.Dll makes the file copied.
Is there any cleaner solution?
Thanks
Unfortunately no, there is no cleaner solution. If no objects from the NLog.Extended assembly are referenced (directly or indirectly) from your code, it will not copy it. This is of course a problem since the layouts are just strings and not a direct reference. You could use a post-build event, but that's an uglier solution in my opinion.
You could add a reference to NLog.Extended.dll in the web project if it depends on it.
I'm using the publishing wizard and it published all of the necessary files except for my Controllers folder. I was under the assumption that I need a controller.
I have navigated to Package/Publish Web setting, do I need to tweak anything in here? I'm guessing this isn't set up properly out of the box. If I change the drop down to publish all files in this folder/solution will it try to upload all the referenced DLLs that don't need to be copied to the server?
In ASP.NET web projects, including MVC projects, .cs files (controllers in this case) are compiled into the /bin/[your.project].dll assembly when you do a Build or Publish.
So you don't need to publish/copy .cs files.
The controller and model code is compiled into the web site dll. The views are deployed in their folders.