I want to rename the Shared folder in my Blazor Server project to Components, how can I do that properly? It seems like namespaces are based on folder names but there must be a way right?
You can just rename the Folder to Components. That does indeed change the namespace, edit the _Imports.razor file like this:
#*#using MyApp.Shared*# -- remove this line
#using MyApp.Components
Related
I have a project solution in visual studio. Its created with MVC .net
I want to move some of my code files such as index.cshtml and others out of the Views>Home folder and into only Views folder. Will this break my project?
Also I want to rename index.cshtml to a new name, throughout all instances in my solution. When I tried this it only did the one file and it broke the project. I tried a CTRL F to find all index.cshtml, but it said there are no instances (though I know there are)
I need to rename the files correctly, so that I can deploy my project to match a current setup.
How do I rename all instances of index.cshtml in visual studio ?
And will moving the files outside of the home folder break the project?
I tried this it only did the one file and it broke the project. I tried a CTRL F to find all index.cshtml, but it said there are no instances (though I know there are)
If you just starting out I'd recommend not moving/renaming view files by hand. Eventually you'll have good understanding of how view discovery works and will be able to move files to places where they can be found at run-time (and even add more places yourself).
ASP.Net is convention-based approach to locate view files - short version is by default runtime looks for .cshtml files with this name format "/views/{controller name}/{action name}.cshtml", you can change view name by specifying different name when returning View("MyOtherView") from controller.
For detailed information on how view discovery works see Order in which Views are searched in MVC, how to change order of search viewLocation in asp.net mvc?, Microsoft - Views in ASP.NET Core MVC.
I have created a scaffolded SPA application where a default UI MVC project was created. I have managed to "scaffold" this where I now have all the .cshtml for account management files locally. I see a "site.css" file loaded from some location somewhere. I want to copy the contents of this file, place it locally -so I can edit it-.
I can simply remove the reference to site.css and add my own *.css reference. But it seems odd that a site.css file is being generated from somewhere and it isn't obvious where it comes from.
The only information I can find on this strange behaviour is:
Where is the site.css file located for Identity?
"you can override those by simply creating files in the same location in your project"
I have tried creating site.css in the "same location"(where is the same location?) but it didn't work. It still loads site.css
[project root]/wwwroot/css/site.css
All public facing files are in the wwwroot folder. So that is where your css, images, javascript, etc. files will go.
Note: "wwwroot" folder is near the top in the Solution Explorer, it doesn't follow the ABC ordering.
I would like to have StyleCop rules apply on a specific namespace (all classes from this namespace are in the same folder).
My project structure looks like this:
Folder1
Class1.cs
Class2.cs
Settings.StyleCop (namespace settings)
Class3.cs
Class4.cs
Settings.StyleCop (general settings)
The general settings are correctly applied to all files (including the ones in the subfolder), but the namespace settings are completely ignored.
I haven't used StyleCop in a while, but I thought this was possible. Am I doing something wrong?
How can I make this work?
I don't think it's possible with Stylecop. I made some experiments and the rule file in the subfolder was always ignored.
I think it only works on a project level. I didn't go through the source code but placed a new C# file under the project without adding it to the project and it didn't analyze it which suggests it finds the code files by looking at the project file and ignoring any files just lying in that folder.
Also if you delete the Settings.Stylecop file under the project folder and select Stylecop Settings in Visual Studio it automatically creates a new Settings.Stylecop file even if you don't save the settings which also made me think it's highly coupled to the project file.
I'd suggest to move the contents of the Folder1 to a different class library and apply a different settings file to that project. You can merge settings with the other project and decide which rules apply to which project.
I am finally done with my ASP.NET Webapplicaton and my solution contains three projects: the webapplication itself, WCF and Classlibrary. But I would like to refactor it to change class names, project names, etc. How can I do this in a smooth way so everything doesn't get messed up, like namespaces etc. I also have Resharper but I'm new to that.
When I renamed my Project file and .csproj etc I still have problems with namespaces the new namespace is not working it asks for the old one.
Thanks in advance!
Right click the Class/Object Name(inside the file) > Refactor > Rename.
It'll ask you if you want to preview as well so you know what gets changed and what not.
To my knowledge, there's no streamlined way to do everything you're asking. As jbkkd mentioned, it's easy to rename classes, but you'll have challenges with the following:
Class file names - renaming a class from the source file will not rename the *.cs filename to match (if the file is open for editing and you rename from the Solution Explorer, it should ask you to rename the class)
You can rename a project name from the Solution Explorer, but this will not automatically rename the namespaces in your code or the physical folder names in your solution (where your project files are contained)
Depending on the type of ASP.NET application, there could be auto-generated files and/or code-behind files that may not have their class and/or namespace name changed; for example, if you change the class name or namespace in a Global.asax.cs file, you have to also make the changes in the Global.asax file too as it will not be done automatically
ReSharper will help with renaming classes and namespaces, etc., but you'll still have to manually clean things up and depending on how big your solution is, it could be a project in and of itself.
About what I read, the EditorTemplates folder must be located under the Shared folder in the Views folder. Is it possible to change this location?
Thank you.
I've always placed my EditorTemplates beneath each view folder they were related too. For example:
If they were "shared" across multiple views I would place them within the "Shared/EditorTemplates" folder.
Is it possible to change this location?
No, that's hardcoded in the MVC source code. Sorry.