How to reuse class library from existing solution - asp.net-mvc

I would like some advice please.
I am about to start a new MVC application using Visual Studio 2013. I would like the new solution to reuse 3 projects (Class Libraries) from an older solution which was created in Visual Studio 2010.
I don't understand how I should reference these 3 class library projects in my new solution. Should I from my new solution:
Add --> Existing Project --> locate the .csproj file of the project I want to reuse
OR
Add Reference --> locate the .dll file of the project I want to reuse
Would either of these be the correct approach?
Any feedback much appreciated.
Thanks.

Related

Filenesting not working for Class or Shared Library Projects

In Visual Studio 2019 Web Projects, file nesting in the Solution Explorer works like a charm. If you add a file named ClassA.cs and another file named ClassA.Custom.cs they get nested as it should be.
But for Class or Shared Library Projects it doesn't work at all. It doesn't matter if you change the settings to "Default" or "Web" or even add a custom File Nesting Setting.
Is there a way, to configure Visual Studio 2019 so that file nesting also works in Class Library Projects and alike?
I know one could change the *.csproj files manually to add Entries with the <DependentUpon> Tag like it was in earlier Visual Studio versions, but i really don't like the idea of changing this manually for all the classes i have.
<Compile Update="$(ProjectDir)\Person.*.cs">
<DependentUpon>$(ProjectDir)\Person.cs</DependentUpon>
</Compile>
For the people using Visual Studio 2022 and non-web projects, this is the solution from Github that helped me to fix it.
To enable configurable file nesting for non-web projects in VS 2022, add this to your .csproj file:
<ItemGroup>
<ProjectCapability Include="ConfigurableFileNesting" />
<ProjectCapability Include="ConfigurableFileNestingFeatureEnabled" />
</ItemGroup>
Original Answer:
There is an issue about this topic active on Github.com and Developer Community:
Issue 5722
Developer Community 483587
A workaround for this problem exists - at least working for .Net Standard 2.0. Add the following lines to your *.csproj file:
<ItemGroup> <ProjectCapability Include="DynamicDependentFile" /> <ProjectCapability Include="DynamicFileNesting" /> </ItemGroup>
Update:
This issue should be fixed from Visual Studio 2019 Verison 16.7 onwards.
Piggy Backing onto #phihi's answer.
#phihi's solution does actually work with .NET Core 3.1 libraries; but in addition, there must be a .filenesting.json file added at the solution level. It seems that it's also required that the new .filenesting.json lives inside a "Solution Items" folder (folder name may not matter) at the solution level.
Desired nesting settings can be optionally defined stand-alone.. instead of creating a new file with ALL existing default settings, as long as you set "root": false - this essentially appends settings onto the existing default configuration without losing any default settings.
Great success 🤘
I faced this issue with the Class Library project on .net6. Instead of using the Class Library template use Razor Class Library.
Template window
You want the Razor Component option to be in place in the Add new item window.
Available item templates

Unable to add reference to certain assemblies in VS2015 MVC project

I am relatively new to MVC, so maybe I am missing something. I am using VS 2015 Community Edition, C# 2015 & .NET Framework 4.5.2.
I have an MVC solution with 2 projects: TLM and TLM.Tests. All the .cs files in both projects are happy with the following line of code:
using System.Data;
In fact, one of the .cshtml files has this line:
#using System.Data;
Now I add a 3rd project to the solution, a Class Library called TLM.Helpers, to hold commonly used code. (In ASP.NET web forms, it would have just gone in a .cs file in the App_Code folder.) However, I cannot add a using statement for System.Data to any of the .cs files in this project. In fact, I cannot even add a reference to that DLL in this project, although I see that there is such a reference in the other 2 projects.
That new project does have successful references to System, System.Collections.Generic, and System.Linq.
Other posts for similar issues suggest verifying that the project is being built for the proper Framework version. The Property page for this project does not even offer the choice of Target Framework. It does have dropdowns for "Solution DNX SDK version", which refers to "Version 1.0.0-beta5". I don't know what that refers to.
Any suggestions as to how I can refer to System.Data in this project?
Thanks.
Dan

Problems after migrating VS2013 to VS2015 in MVC

UPDATED QUESTION
I have a project that I've started in VS 2013 and was setup as the following:
MyMainMvcApp (Containing core Functionality)
MyPlugin (Containing plugable customer stuff)
MyPlugin contains some *.cshtml views as embedded resource and some controllers.
In VS2013 I was able open the Views and i had full Razor Intellisense and no issues when compiling.
IN V2015 the Error List is showing a lot of errors like
Feature 'lambda expression' is not available in C# 2. Please use language version 3 or greater.
The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
etc etc
Of course I have all the Assemblies referenced. And the projects even compile.
I believe that VS 2015 is just missing some config stuff in web.config or similar, so that he can resolve the stuff while having the view open in designer.
I have an app.config in MyPlugin project that has been added from Nuget.
I've put the same config stuff as my web.config in there but that didn't help.
As well I copied the MyMainMvcApp\Views\web.config into MyPlugin\Views\web.config that didn't work as well.
Any idea what the issue might be or ideas how to solve it?
I've started MyPlugin as a Class Library in VS 2013 and that worked well. Afterwards I was not able to make MyPlugin work as desired in VS 2015 designer. I've created a new MyPlugin Project as a MVC Project and copied all my code from the old library to the new.
It's a workaround but that solves my VS 2015 problems.
The fact that it's trying to utilize C# 2, is pretty concerning. Make sure your project is targeting the latest version of .NET you feel comfortable with. Since you're using VS2015, go all the way to 4.6 if you like, or if you want something a little more hardened, stick with 4.5.2. Just right-click your project in the Solution Explorer and choose "Properties". Then on the first "Application" tab, change the "Target framework" drop-down to something appropriate.

ASP.NET MVC source code missing solution file

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

Visual Studio 2010 Automation for ASP.NET MVC

I'm new in automation and I could'n find some tutorials or guids how to do that. I found that I could write add-in for visual studio and found that guidance automation can do something what suits me. I tried to create guidance automation project in Visual Studio but some notes in project pointed to Visual Studio 2005. And project icon seemd quit old style. So I thought maybe it's dead.
I would like to do some automation for my mvc project. I have to do a lot fo similar forms. So I decided it would be great to havo some automation. Things I would like to do:
when I'm creating controller I would like to select entity
create controller class from my defined t4 template
create tests in my test project from t4 template
create model class in Model folder
ceeate command class
In your opinion what would be best solution to aproach that?
And maybe anyone knows any resources where to start.
Thanks
Have a look at the Mvc Scaffolding package available through nuget.

Resources