I made arrangement in my solution. I made seperation of projects and reorder directories. Now my namespaces are messed up. Is there any tool that will arrange the namespaces according to the position of the file in the project?
For example, if a cs file is in Printers/Pdf directory under MyProj project, I would like the namespace of the classes in the file will be MyProj.Printers.Pdf.
EDIT: I am looking for free tool if possible.
Resharper can do this, though it's commercial. But there is a trial version.
Resharper > Right click on the project > Refactor Menu > Adjust Namespaces. This will re-arrange all namespaces according to folder structure, as it should be.
Resharper can do this as well as update the using statements in all files which use those classes.
Resharper is the best option and is well worth the money. If you have paid the costs for Visual Studio, a Resharper license cost will feel like pennies.
As for free options, I think a project wide, find & replace might be your best bet. You could find what the incorrect namespace is, then folder by folder find it and replace it with the correct one. If you just moved it to a different project, you could just search for...
namespace MyOldProject.
and replace it with...
namespace MyNewProject.
This is assuming you kept directory structures.
Related
I am handling a big WPF application that contains more than 100 projects and and 100s of classes. To modify some areas, I need to find the xmal files and the right projects, classes and namespace. Unfortunatelly, naming is not always helpful. Is there any helpful options in Visual studio.
You can use the search input in the solution explorer tab on the right
You can use view class diagram for this. You can check how to install and run the component from the link below. I hope it solves your problem.
https://learn.microsoft.com/en-us/visualstudio/ide/class-designer/how-to-add-class-diagrams-to-projects?view=vs-2019
I downloaded Unity 20.2 and want to use namespaces for my code. I modified my project settings to this
In the editor I now have this folder structure for my code
The problem is that the created script Test has the namespace Sources although I would expect it to be Sources.Scripts. I also tried Assets.Sources but it still is not able to create Assets.Sources.Scripts from it.
How can I achieve this?
If you create a class in Visual Studio, then it automatically gets the namespace from the folder structure. Like assets.scripts.something. Just create classes in the correct place and you will get all needed namespaces.
I'm going to describe a situation with some packages in a project to explain this:
Imagine a project in Unity3D with a directory structure like this:
Assets
Resources
Scenes
Source/Scripts
UI
Buttons
Modals
Namespaces convention in this case is driven by the programming language used (C#) in the project (First letter in uppercase, matching the name of the folders).
I suggest you to ignore the directory path until the "Source" or "Scripts" folder when you are choosing the namespaces of your packages. Then in this project we would have this 2 packages:
ProjectName.UI.Buttons
ProjectName.UI.Modals
Conclusion: Write your own namespaces, because Unity namespaces generation is based on folders structure from root and I think that is not the best if you want to share your code by modules, for example.
Good luck, bro 💚
If you are using Rider , then try this. Resharper has the same option. I don't use neither of them , so , have to use Select(Assets) + Del everytime making a new class.
I'm working on a project that references a dll that has been obfuscated. The dll has many namespaces and classes that are single letters.
My issue is that many times while typing, Resharper will suggest classes from this assembly, e.g. if I am typing 'Report' it will suggest 'r.e.p' from this other assembly.
Is there a way I can get Resharper to ignore this one particular assembly for intellisense options?
Thanks
It is not possible now - there is the same feature request.
If your source code is located under a single parent directory, Resharper allows you to exclude it:
Goto Resharper -> Options, Settings, then press the 'advanced button'
There you can enter the directory and/or files to exclude from the solution wide analysis.
Go to Resharper > Options > Intellisense. Just look at it if you can find what you are looking for.
I have a big solution with about 250 projects.
I need to change the prefix of solution (my company name) from "X" to "Y".
Of course some of the projects' names start with the prefix - X.Utilties, X.Dal...
Means I should change project namespaces, assemblies, folders and references and even injection (IoC).
What is the best and safest easy way to do it?
I´d suggest getting the trial version of Resharper and using the available refactoring tools to change all namespaces.
From the top of my head you´d do it this way:
Manually edit your project files to have the new name (or do it with find/replace)
Reopen the solution in visual studio
Right click on the solution > Refactor > Adjust namespaces
I just opened a solution from TFS using Visual Studio 2010. The solution contains more than 100 projects (if up to me, it would probably be less than 5) and many of them happen to miss a reference (to Unity dll's).
Is there any way to simplify the fixing of these references? Now I have to delete and re-add all of them manually. Hassle.
Any suggestions would be appreciated.
To fix the problem you need to find out from where it tries to load the files. You can do so looking in the project csproj file. You either have newer (or different) versions of the assemblys installed or you have a different file and folder structure. You need to recreate the file and folder structure that has been used in that project or rewrite the csproj file to the new location.
For the future you might want to change how 3rd party references are handled. I have good experiences using this approach: Define a ThirdPartyLibraries Folder where all those libraries go and check it in. It should be in the solution folder. Everybody has to put 3rd party libs in there from now on and use them instead.
Might want to check out resharper, it might do what you need for references. I know it helps optimize and identify references in classes, not sure at the project level. Resharper has a 30 day trial
You can add all those binaries in to Binaries folder and add in to your TFS.
Now add the binaries as existing item in your solution items, so that when you open the solution it fetches all the solution items as well.
Make sure the references are added from the binaries folder.
If the location of the referenced assembly has changed, then it is relative simple to do a Find and Replace in files on the .csproj files to replace the broken reference with the correct one.