My team has multiple web application projects that have common components. In order to keep from having multiple instances, we have setup a common source that contains common classes and web project. In the web project, we would have MasterPage, pages, and user's controls that are shared as linked files from the main web application. each of the shared projects are included as part of the solution. The solution builds successfully, but when I open the page of the web app, I'm getting server stating that "The type 'Common.Controls.Master' is ambiguous: it could come from assembly 'C:....\bin\Common.Controls.DLL' or from assembly 'C:....\bin\AppWeb.DLL'. Please specify the assembly explicitly in the type name."
The actual Common.master resides in the Common.Controls project at the root. The link file to the master page is in the AppWeb project.
I've looked for solution and found this How to share Master Pages between my projects which is pretty much what I'm doing.
Another option I found was What is the best way to share MasterPages across projects. I haven't tried the methods in this one.
I was certain that using the linked file would work.
Thanks in advance in helping me resolve this error.
I faced a very similar issue recently with a different shared class.
Is it possible that the initial location of the MasterPage was under AppWeb project and then moved under Common.Controls project? In this case a build would not clean the previous dlls and would cause the error you are looking at. If this is the case, a simple manual deletion of all files under the bin folder of your projects and rebuild should solve the issue.
I hope this helps
We have a big project developed in Asp.net MVC5. Our models and business logic are defined in separate class libraries. Now we need to add another module to an existing project but we want a separate dll.
This module also shares the most javascripts, css files and other files. That is the reason we don't want to separate MVC project.
Is there any why we can create separate dll for module basis. so we don't want deploy or touch other dlls.
From your description, you say that the projects share CSS and JS files. This leads me to believe you are talking about a separate MVC website (possibly part of the larger corporate website). This can be easiest with the use of Areas. If you are not familiar with Areas, please read the following: https://msdn.microsoft.com/en-us/library/ee671793(VS.100).aspx
Of course using Areas will require you to deploy the whole site everytime one of the areas change, and you have mentioned that you want to avoid doing so.
If you don't want to use areas, and instead want to create another MVC project in the same solution, you can do that easily too. You can right click on the solution, add new project > ASP.NET web application > MVC to add the project. To share JS and CSS files between these two MVC projects, you will have to create a new solution folder (right click solution > Add new solution folder), and move your resource files to that folder. Inside each MVC project in your solution, you will add existing items and select those js/css resource files. This way if you change the css file, it will be reflected in both the projects.
For more information, read the following:
How do you share scripts among multiple projects in one solution?
Yes you can, just add the logic classes to other class library project (you can have as many as you want), then add references of those class librarys to the mvc project.
Don't forget to import the classes after in your code
Edit: I'm assuming you are using Visual Studio, if yes, you can go to File -> Create Project, this will create another project in the same solution.
I don't know whether you tried with Managed Extensibility Framework (MEF) or not.. this framework works as you required ... I think below link will help you more
ASP.NET MVC Extensibility with MEF
How to integrate MEF with ASP.NET MVC 4 and ASP.NET Web API
http://www.codeproject.com/Articles/167321/MEF-with-ASP-NET-Hello-World
Other people have posted answers regarding the use of Areas. Areas are great and good and helpful. They really benefit the project structure.
This module also shares the most javascripts, css files and other file
The title of your question is about .dlls, but I suspect the client-side resources are the main concern.
If you consider your webapp as having two distinct parts: server-side and client-side, you can use appropriate strategies to modularize each. Areas a great for organizing server-side code, but don't help the front-end.
Front-end package management options have expanded for ASP.NET 5. In addition to the traditional NuGet package manager, Bower and NPM are now supported. For example, consider how this article demonstrates installing jQuery via NPM. Here's another good article about setting up NPM, Bower, and Gulp in Visual Studio.
What to do: Take your existing client-side code and make a custom NPM or Bower package, and then use that package from one or more Asp.NET projects.
I can suggest you two ways to organize your multi-module project.
Option 1 - Create Area per module, within same web project
One way to do it is, create separate Area within the same MVC project. So each module will have a separate area, with separate controllers, views, scripts etc. But,
(1) This will still create a single dll for the whole MVC project
(2) Sharing files across areas might not be very easy in some scenarios (you can keep all the scripts for all the modules in one shared directory though)
Option 2 - Create class library per module, merge after build
Another way is to create a single class library project per module. Add reference to the System.Web.Mvc and other libraries so that it can have controllers etc. Create your own views, scripts and other folders and populate with files as you need them.
Now, all your modules will build as separate projects, with the dll file and the javasvripts, htmls, csss, images etc. To make them all work as a single web application you can create a (only one) MVC web project, which will go to the IIS virtual directory and will be published as web.
To use all your separate modules from the same web, you can write post build events in all those libraries to copy the artifacts (dll, scripts etc.) into the main web, into corresponding folders (dll to \bin, javascript to \scripts etc.). So, after successful build, all the artifacts are available in the same web project, and that can be deployed as a single web with all the modules. Your post build scripts should look something like this
XCOPY "$(ProjectDir)$(OutDir)*.*" "$(ProjectDir)..\YourMainWebDirectory\Bin\" /Y
XCOPY "$(ProjectDir)Content" "$(ProjectDir)..\YourMainWebDirectory\Content\" /S /Y
XCOPY "$(ProjectDir)Scripts" "$(ProjectDir)..\YourMainWebDirectory\Scripts\" /S /Y
XCOPY "$(ProjectDir)Views" "$(ProjectDir)..\YourMainWebDirectory\Views\" /S /Y
XCOPY "$(ProjectDir)Images" "$(ProjectDir)..\YourMainWebDirectory\Images\" /S /Y
Now,
(1) You have separate dlls for separate modules
(2) Can directly share scripts and other files, as they will be in same location (after build)
(3) If you decide to remove a specific module from the web, just remove the post build event from that module (project) without affecting anything else. You can add that back at any time you please.
Your overall solution will look like
Module01.csproj => post build copy to main
\Controllers
\Scripts
\Views
\Contents
\Images
Module02.csproj => post build copy to main
\Controllers
\Scripts
\Views
\Contents
\Images
Models.csproj
\...
Application.csproj
\...
Main.Web.csproj => main web application hosted in IIS
\Controllers
\Scripts
\Views
\Contents
\Images
I currently have two MVC projects in two solutions which will share a fair bit of look and feel but very different functionality. As such they have different solutions to manage their code. Everything is being stored in TFS repositories.
Currently any shared C# code is managed through class libraries and while this is great for the C# code there doesn't appear to be a similar way to do this for JavaScript or CSS files. Is there a best practices way to handle shared JS and CSS files between separate solutions in TFS specifically or just in solution files in general?
To be clear what I mean when I say "shared," it should have the following criteria:
File has the same name in both solutions.
Editing the file in solution A results in those changes being applied to that file in solution B.
Ideally this will be transparent to the developer.
You can create a separate project (say "CommonJsCss") that contains all of the shared .js and .css files. Then just include that project in both Solution A and Solution B.
why don´t you put your files in a folder, let´s say 'c:\myprojects\shared\javascripts'
and include the folder in all the solutions you need it to be?
all code changes will be usable for the other project. Also, you can define your own bundles in each solution including those files.
I have a few MVC3 projects that uses the same partial views. These views contain parts of forms that i can easily reuse in other MVC projects. is there a way to centralize Views. Like, in another project perhaps? So i can add the assembly of the project and easily call the views i need?
Otherwise i have to copy the reusable views folder every time i start a new project. And when i make a change to one of those views, then i have to change it in all the other projects too. Would be better if i could put it in one place and reference to it somehow.
Is this possible?
The easiest solution is to simply map a shared virtual folder in your views folder, using IIS's virtual folder feature. That way all apps that use the same views will actually point to the same physical folder.
You may have some challenges with deployment, and you could make the shared folders part of their own project. But you will need to deal with that both on the local dev machine and the server.
My web application (ASP.NET v3.5 / C#) dynamically creates other asp.net applications (creates aspx, aspx.cs, classes, web.config, project.csproj file etc.).
The thing is even after I configure the 'new' application folder as APPLICATION in the IIS, When I try to browse it, I get the following parser error: Could not load type 'Template48.Template48' (where Template48 is my application).
When I manually browse to the new application folder, and re-build it, all works perfect.
How can I re-compile this WHOLE application, but in it's folder ?
Thanks in advance,
Gal.
A web application needs to be compiled before it works; this is different from a web site.
Just providing the sources isn't enough; in fact, ASP.NET doesn't need the sources (aspx.cs) to run the application, just the .aspx, web.config, and .dll files ("assemblies" in .NET lingo). It is even considered good practice to remove the sources from the production system to avoid accidentally leaking the sources and giving attackers information about the site's inner workings.
To make this work, you need to somehow invoke the command-line C# compiler to build the project on the fly; this will generate the needed .dll files.
A different, but much harder, route would be to use .NETs ability to emit IL at runtime; using this facility, you could produce assemblies directly without going through the compiler. This is pretty difficult though, and you need thorough understanding of the IL to pull this off.