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
Related
We have an issue with Visual Studio 2019 found when trying to pre-compile our ASP.Net project during publish. We got errors such as:
error CS1056: Unexpected character '$'
When I look at the view, it is using string interpolation.
All the projects in this solution are set to target full .Net Framework 4.6.1. From what I read, that should default to C# 7.3 compiler.
I have updated the DomCompiler and Compiler packages to version 3.6.0. In the web.config I tried to set c# version to both default and 7 specifically. The error occurs no matter which one is used.
I also tried to add LangVersion to the .csproj file and specify 7, but that didn't work either.
If we deploy not pre-compiled these views work, so the run time on the server is usually the correct c# compiler version. This is only a dev time and build time issue.
Visual Studio 2019
Visual Studio 2019 chooses the language version by default:
Right click on your project and select Properties
Choose Build and click the Advanced button
click on Why cant's I select a different version?
The latest C# compiler determines a default language version based on
your project's target framework or frameworks. Visual Studio doesn't
provide a UI to change the value, but you can change it by editing the
csproj file. The choice of default ensures that you use the latest
language version compatible with your target framework.
If you want to override the language version you have 3 options:
Manually edit your project file.
Set the language version for multiple projects in a subdirectory.
Configure the -langversion compiler option.
The first option seems to achieve your goal, open the project file in your favorite text editor and add the language version, e.g:
MyProject.csproj
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<!--<LangVersion>preview</LangVersion>-->
<!--<LangVersion>7.3</LangVersion>-->
</PropertyGroup>
</Project>
Visual Studio 2017
Right click on your project and select Properties
Choose Build and click the Advanced button
Here you can choose your Language version
Change language version for all of the projects at one go
If you have several projects in your solution and you want to create a configuration to change the language version for all the projects at one go, then you need to create a file name Directory.Build.props at the root of your repository. You can configure the language version in this file, for example:
Directory.Build.props
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<!--<LangVersion>preview</LangVersion>-->
<!--<LangVersion>7.3</LangVersion>-->
</PropertyGroup>
</Project>
See this question for detailed explanation.
You can not use c# 7 with .Net framework projects targeting 4.6.1. It does not matter which visual studio version you're using.
Please check this link:
https://www.tutorialsteacher.com/csharp/csharp-version-history
I had the same problem (not being able to use all language features) while using (.net 4.5.2)
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.
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.
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
Using the latest stable of CC.NET (new to it) and VS 2010.
I have defined project files for simple C# projects (4 in total) and one MVC Project.
The C# projects all compile correctly; however, the MVC3 project refuses to build.
I receive the following error in CC.NET:
error MSB4019: The imported project
"C:\Program
Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path
in the declaration is
correct, and that the file exists on
disk.
After searching around and finding This link
and This other link (both referring to older versions of Visual Studio), it seemed that the general solution was to copy these files from that directory to the solution directory, add them to the solution with visual studio, and then change this line in the .csproj file:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
To this:
<Import Project="$(SolutionDir)\Microsoft.WebApplication.targets" />
However, this technique that worked for other VS Versions produces a different result in VS 2010: I receive the .NET Project upgrade wizard, as if upgrading the project from an old version of .NET. This strangeness is compounded by the fact that even if I do an undo and re-save the file exactly as it was, I receive the same message. It's as if the project has been marked dirty or something else has changed somehow.
Anyone have any ideas? This seems like it should be easier, but I can't seem to find another resource on it anywhere. Hoping StackOverflow will come through per usual. :)
Thanks in advance for any help!
The .targets file for v10.0 also has an assembly in the install folder - Microsoft.WebApplication.Build.Tasks.dll. Did you copy that file over as well? That will likely be necessary for the .targets file to work correctly, though that may not be the cause of your problem.
It sounds like CC.Net isn't getting a proper reference to the msbuild executables.
Trying installing both of these on your build server (that's who I was able to get past that exact error).
Links :
Windows SDK .Net 4
VS2010 Integrated Shell