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.
Related
We have a scenario like this:
We have ~100 solutions containing 10 projects each.
Each solution copies its artefacts (i.e. its 10 dlls) to a shared single folder like C:\code/assemblies.
If I develop something for feature X, I'll open up SolutionX.
The source for all solutions/projects is local in a single Monorepo C:\code.
During debugging, when the method/class/whatever is implemented in project Y, it opens the corresponding file (which is nice). So there must be information available how to get to the source.
But when developing, I cannot navigate to the implementation e.g. by using F12 ("go to definition") but just get the signatures gathered from meta data. I'd like to have the same experience like during debugging.
So right now I open up a Visual Studio Code, open the folder containing the sources and do a "search in files".
Any better ideas?
N.b. Resharper is not an allowed option. Also doesn't play nice with Postsharp.
N.b. I don't know if it is important but all except one solution start an external program (the shell), since all except one solution contain only dlls.
I have done similar in Old project.
You can use Symbol with Visual Studio 2019. Simple steps can be:
A. Generate Symbols for projects :
In Solution Explorer, select the project.
Select the Properties icon (or press Alt+Enter).
In the side pane, choose Build.
In the Configuration list, choose Debug or Release.
Select the Advanced button.
In the Debugging information list, choose Full, Pdb-only, or Portable.
Refer for more information:
Set debug and release configurations in Visual Studio
Publish symbols for debugging
B. Use Symbol in Visual Studio:
In Visual Studio, open Tools > Options > Debugging > Symbols (or Debug > Options > Symbols).
Under Symbol file (.pdb) locations,
To use the Microsoft Symbol Servers or NuGet.org Symbol Server, select the checkbox.
To add a new symbol server location,
Select the + symbol in the toolbar.
Type the URL (http), network share, or local path of the symbol server or symbol location in the text field. Statement completion helps you find the correct format.
Tools - Options - Debugging - Symbols page
For more Details refer:
Configure symbol locations and loading options
I think you should analyze project dependencies (for example with https://www.ndepend.com/docs/visual-studio-dependency-graph ) and cluster your projects in less Solutions
Edit : I am editing this answer based on your comment. I think you are looking for two use cases
Peek into the source code of referenced binaries
Navigate to the source and then edit them in place
To achieve option (1)
In Visual Studio 2019, use the built in decompiler to help you with navigating to code outside of the solution. This is an experimental feature as of May 2020. By default this is disabled and you should enable it. Once enabled the F12 navigation will decompile and allow you to peek into the source code.
On the other side, the more you relax the compilation the better the decompilation. Meaning, you can turn off optimisations (if any). This doesn't have to do anything with symbol generation options.
If you are using visual studio 2017 (or) less, the same can be achieved by Telerik Just Decompile plugin (free). Check the feature View decompiled code in tabs
To Achieve option (2) :
You should reference source files rather than binaries, because you won't get the natural in-place edit with referencing binaries. There are always going to be caveats irrespective of the solution you choose. Referencing source can be done using the "Add as link" feature in Visual studio, where the source code belong to one solution and can be referenced as link (something like windows shortcuts) in all the other solutions. (https://andrewlock.net/including-linked-files-from-outside-the-project-directory-in-asp-net-core/). If you are referencing source, you need to remove the binary references.
And you also have to decide from an architectural standpoint on how this changes the way people develop and commit code. The point of referencing binaries is to make sure they are not edited for convenience, but that depends on the nature of the development team purely.
Conclusion
From a best practices standpoint, you either have to reference binaries and don't allow them to be edited (or) you allow source references and edit in place. But that depends purely on what you want to achieve.
On a certain solution the "Remove and Sort Usings" option does not work.
It sorts the Usings correctly, but does not remove any unnecessary ones.
The IDE is flagging the unused ones correctly, but it can't seem to remove them.
No errors or messages are displayed anywhere, it sorts and behaves like it has completed successfully, but the unnecessary Usings remain and are still flagged by Intellisense as such.
I have verified that in a different solution it does work, so it is not my VS2019 install.
And I don't have any plugins installed (like Resharper) that could conflict.
Have also tried clean and rebuild in case it needed an error-free compilation to work with.
Any ideas what could be different/special about a certain solution that would prevent the remove functionality?
I have found another thing which causes this issue.
For me, I discovered it was only happening in 1 particular project in a solution.
After comparing the non-working csproj to a working one, I determined that the difference was the Warning Level.
The non-working one was set to 1.
Resetting this to the default 4 allows the Remove and Sort Usings function to work as expected.
I found the cause, and it's an annoying one!
There is a custom ruleset specified for static analysis of the projects, and that had both CS8019 and IDE0065 (Unnecessary using directive) unselected.
On selecting these the remove unused usings command worked again.
Thanks to other answers for suggestions.
I had the same problem and figured out what was wrong. In your Tools|Options|Text Editor|C#|Advanced look for theses settings:
HTH.
Any ideas what could be different/special about a certain solution
that would prevent the remove functionality?
This is quite a strange behavior. You could try these suggestions:
1) close VS Instance, delete .vs hidden folder, bin, obj folder.
2) clean vs component caches under C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\16.0_xxxx(every this folder)\ComponentModelCache
3) use devenv /safemode to start VS IDE, open your project and then test again.
4) If your project is an old project which means that the project structure is a bit different from VS2019, please try to create a new vs2019 project and then migrate its content into the new project.
In addition, if these do not work, you can try this link's function to run Code Cleanup command with remove unused usings.
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 have two very long and detailed .csproj files.
I want to combine them into one.
I used text comparer but the items are not in the same order
and it's hard to isolate differences.
How would you recommend to combine them?
(they have compile, include, post build and after build events)
edit:
I want to merge 2 unrelated projects with some common dependencies
Copy the files from project 1 into the project 2 folder. Then turn on "Show all files" so you can see the files that aren't in the project. Then right-click each file and choose "Include in project".
I would probably do most of this in Visual Studio. You can either drag the files you need from one project to the other, or you can copy all the files from one project folder to the other in the file system and turn on "show all files" in the solution explorer to show which need to be added. You will then need to align the namespaces. The Class View window can help identify types which do not fall inside the right namespace. A refactoring tool like Resharper can also help fix up the namespaces.
If you have explicit pre or post build events in each project, I would use the VS GUI to show these and manually combine. If you have custom build targets/tasks in the files, I would isolate these in a good text/XML editor and manually union them as required.
The other thing you will have to do is to add references to the final project which it did not originally require but were required by the other project. It should be quite quick to identify which references need to be added, by attempting compilation and inspecting any errors.
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.