How do I reformat MSBUILD xml in Resharper or VS Studio? - visual-studio-2010

Both ReSharper 6 and VS 2010 treat my MSBUILD files as XML when it has the .Proj extension, but it will not allow me to reformat the text. The options are greyed out in ReSharper and VS 2010. How do I turn it on? Right now, I am forced to either copy and paste the code into a file with an xml extension reformat and copy and paste it back, or rename the file with an xml extension.

You can write a Visual Studio macro that will do all the renaming and reformatting for you. Macros can be bound to the toolbar and to commands (keyboard shortcuts), so you can make this into a single click/shortcut.

JetBrains answer as of today (2013-12-02) is that project files are excluded from code cleanup. There's a discussion of the issue on their code cleanup page which contains a link to a bug named Verify that Code Cleanup works with MSBuild .proj files which contains the information that the fix version is only 9.0!
So there seems no way short of an external tool to get this done.

Related

how to get color code on my code FOR EXAMPLE (Debug.Log) to be in a color?

s
I want someone to tell me how to put colors on the code so its easier for me to code.
I think you forgot to select unity c# components when installing visual studio,
try again with visual code
If you are talking about Intellisense / syntax highlighting, you need to make sure that you installed Visual Studio Tools for Unity (Note this is needed for Visual Studio only and you may already have it installed).
Then follow these steps:
Close Visual Studio
In Unity, go to Edit > Preferences > External Tools
Click on the External Script Editor dropdown (this should be on which ever Visual Studio editor you are using or any other supported editor).
Make sure Embedded packages and Local Packages is checked under Generate csproj files for:
Click on Regenerate project files
Open any C# script and check if syntax highlighting is working.
In the worst case, if that does not work, you can close Unity and delete everything except the Assets/ and Project Settings/ folders (as well as anything you explicitly added) in your project's root directory. Unity will regenerate the project folders and files again when you open the project in the editor. It may just be that some of your project files were corrupt.
Also, in case I misinterpreted your question and you are talking about coloring the output in the console window within the editor, you can try using rich text which I believe is supported by Unity's console window in the latest versions.
Example:
Debug.Log("<color=red>this is red text</color>");
For more info on that:
https://docs.unity3d.com/Packages/com.unity.ugui#1.0/manual/StyledText.html

Refactor on save in Visual Studio 2019

I love Prettier for VS Code. I want to do similar things in Visual Studio (2019).
It now has 'Wrap, indent, and align parameters or arguments' for example (https://learn.microsoft.com/en-us/visualstudio/ide/reference/wrap-align-indent-parameters?view=vs-2019); and I'd like to do this automatically whenever I save the file.
Does anyone know if this is possible? Or if there's a free extension that can do this?
Mads Kristensen (a Microsoft employee who makes scads of Visual Studio extensions and teaches you to too!) made a JsPrettier extension for "classic" Visual Studio (ie, not VS Code):
https://github.com/madskristensen/JavaScriptPrettier
It does not format on save if you set that up in its settings.
If it's literally Prettier in Visual Studio that you're after, this isn't a bad option.
I don't know of a free plugin but you can get quite a long way towards this with some muscle memory and the built in autoformat command.
CTRL+E, CTRL+D, CTRL+S
will do code indentation and formatting, and save the file.
If you have Resharper (sorry), there's a configurable code cleanup tool which will do what you want and CTRL+E, CTRL+F, CTRL+S will do the cleanup and save.
The Format document on Save VS extension does exactly what you want, with one exception. It automatically runs Visual Studio's code cleanup command on save.
Visual Studio's code cleanup commands covers many code style preferences and can be configured with a .editorconfig file. Unfortunately one thing that is not supported by VS yet (not counting Resharper) is line wrap preferences. There is an open ticket for this: dotnet/roslyn#33872
If and when Roslyn supports line wrap preferences (presumably as a new .editorconfig preference), then Visual Studio code cleanup will enforce it and the extension will apply it on save.

Replace tabs with spaces in Visual Studio project files (sln & vcproj)

I'm trying to have a strict no-tab policy at my company by adding blockers on commits which introduce tabs.
Problem is visual studio uses tabs for their .sln & .vcproj files even when your settings are set to use spaces instead of tabs in the VS editor.
Anyone know how I can change that or am I stuck making another microsoft exception?
For your information, spaces are supported in vcxproj but not in sln files. Replacing tabs by spaces in .sln will make it load incorrectly (not generate exceptions or anything).
There are no settings in visual studio itself to change that though.
There are scripts that can do it before submitting in a source control but keep in mind that .sln files must keep the tabs to work correctly.
This is fixed in Visual Studio 2019.

How to debug Visual Studio extensions

I'm just writing a VSIX extension for Visual Studio 2010 and can't figure out how to debug it.
One obvious method is to output messages. Extension template uses Trace.WriteLine(). But where to find it's output?
Visual Studio Extensions can be debugged like any other application. You just need to setup the debug experience to launch devenv with the loaded extension. Try the following
Right click on the project and select Properties
Go to the Debug Tab
Click on the radio button for Start External Program. Point it to the devenv.exe binary. On my machine it's located at
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
On a non x64 machine though you can remove the " (x86)" portion.
Then set the command line arguments to /rootsuffix Exp. This tells Visual Studio to use the experimental hive instead of the normal configuration hive. By default VSIX extensions when built will register themselves in the experimental hive.
Now you can F5 and it will start Visual Studio with your VSIX as an available extension.
The accepted answer by #JaredPar is technically correct, but suffers from the fact that you need to redo it for every developer, every time you get a fresh copy of the code, and any time the csproj.user file is deleted. When you do it that way, the settings are saved in the csproj.user file.
A better option is to put the settings in the csproj file so they are not lost. Unfortunately, Visual Studio does not allow you to do this automatically, so you need to manually add the settings. Luckily, the settings are the same for any project.
Right-click and unload the project, then right click again and edit the csproj project file file. In the XML, add the following to the first PropertyGroup, for example right after TargetFramework.
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
This has the following advantages;
It sets it up for debug and release
It runs whatever version of Visual Studio you are currently running
It is checked into source control, so every developer doesn't have to remember how to do it :)
As #MBulli states in the comments, if you have made the changes in the accepted answer, delete your *.csproj.user file because the settings in it will override the ones you added to the main csproj file.
The OutputWindowHelper.OutputString method writes to the 'General' output window pane (Ctrl Alt o). I added this line in my .csproj references to get this in VS 2013
<Reference Include="Microsoft.VisualStudio.Services.Integration, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
Also see this answer.
If you try to debug a UnitTestExtension, you should also attach the debugger to the vstest.*.exe processes like descibed here. Otherwise you might see the activate breakpoint but the debugger will never hit it.

How to reload a property sheet in Visual Studio 2010

Is there a way to reload a property sheet that was edited outside of Visual Studio? Visual Studio doesn't detected automatically that the file was modified (like it does with project files). The only way I've found so far is to close and reopen the whole solution (but that's no good way).
Only a partial solution perhaps for your (and my) needs, but I've found it helpful to touch the .sln file. This causes Visual Studio to wig out and ask if you want to reload all the projects. Select "Yes" and then you'll notice the properties have refreshed. I make sure that my scripts which update property files also touch any related solution file(s).
Also see Is there any way to get Visual Studio to reload all projects when the .proj files have changed?

Resources