Can Code Style preferences be shared? - c#

I've read that VS2017 supports .editorConfig and that you can create your own .editorConfig files at solution/project level and share them, however, I am wondering if the machine/user -wide configuration can somehow be shared?
I mean these settings:
Or am I completely wrong in thinking that these settings are related to the new .editorConfig support?

Yes, you can. You should go:
Open a solution in Visual Studio.
Go to "Tools"
Go to "Import and Export Settings"
Choose Export
Follow prompts.
If you follow the export, you'll see that it exports those configuration settings into the script to parse and read when imported into another instance of Visual Studio.

Related

Setup C# solutions startup projects in a configuration file

I have a solution with 4 projects in it. I wish to start them all.
For example, I had somebody new clone by work. This means that startup projects wouldn't be configured. However what I want is a file that defines what startup projects should be set when you run for the first time.
From what I found this information is written by Visual Studio to *.suo file in .vs directory that Visual uses to store some user solution settings and options.
Maybe you could develop Visual Studio extension that could persist selection of start up project. You can find some information here.
More about .suo file in this SO post.
Solution explorer > "yourcoolprojectname" right click> properties> common properties> multiple startup project> choose projects

Suppress a warning for all projects in Visual Studio

I've seen answers showing how to suppress a warning for a specific line of code or for a specific project. I don't want that.
I want to suppress a specific warning for all of my projects.
(If it matters, the warning is IDE0044. And I'm using C#.)
A recent update to Visual Studio 2017 (15.7.1) has an option for this now. Under the Tools->Options menu, select the TextEditor->C#->Code Style->General tab. Under Field preferences, there is a Prefer readonly option. Set that to No.
There is also an editorconfig setting you can set if you want to check this preference in along side your code, so others who consume your code don't get the warning, but that has to be done on a per solution basis. The editorconfig value you would set would be:
dotnet_style_readonly_field = false:none
You can use the SuppressMessage attribute present under System.Diagnostics.CodeAnalysis namespace like
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "args")]
Well as you have edited saying I want to suppress a specific warning for all of my projects
You can't do that for a entire project wise AFAIK. But check the linked post once if that helps
How to suppress code analysis messages for all type members?
To suppress warnings for all projects, you need to create a .editorconfig file in a top-level directory. For example, I have mine in trunk and I commit it to source control so that my colleagues share the same settings.
The settings in this file apply to all projects in trunk and subfolders, unless overridden by another .editorconfig file further down the folder tree e.g. you might you have a project specific EditorConfig file in a subfolder which has different settings. See File hierarchy and precedence for more details.
Creating an EditorConfig file
You can use a text editor for this if you just want to change one specific setting. However, Visual Studio can create a .editorconfig file with sensible defaults for .NET for you. From MSDN:
Create a new project
From the menu bar, choose Project > Add New Item; or press Ctrl+Shift+A
Select the editorconfig File (.NET) template to add an EditorConfig file prepopulated with default .NET code style, formatting, and naming conventions
Optionally delete the project - we don't really need it
Visual Studio 2019 - Creating an EditorConfig file from current settings
In Visual Studio 2019, you can instead create an EditorConfig file from your current settings. Just click the following button in the Options dialog under Text Editor > C# > Code Style > General:
If you're creating in a text editor you'll probably need this at the top of the file, adjusted as necessary:
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
# C# files
[*.cs]
Disabling IDE0044 in the editor config file
To disable IDE0044 specifically, add or change the following setting in the .editorconfig file:
dotnet_style_readonly_field = false:none
(In Visual Studio 2019, you can set the Prefer readonly option to No under TextEditor-> C# -> Code Style-> General in Options and then press the Generate .editorconfig file from settings button as detailed above).
You may try to use Directory.Build.props adding NoWarn property for specific warnings. I haven't verified it though.
And as it's said in another answer, it's better to fix the root cause instead of ignoring it.
I would like to add to Stephen's post that his solution with the .editorconfig file didn't work out for me without specifying the files I want to apply the rule to. For example, and given that I want to apply a rule to all the test files and that I follow a naming convention in which these end up with "Tests.cs", I have managed to ignore the CA1707 rule in those files by using the following rule:
[*Tests.cs]
dotnet_diagnostics.CA1707.severity = none
More information on my answer here
IDE0044 is "add readonly modifier" so why not just add the modifier?
Warnings are telling you that you're doing something wrong, but the app will compile.
It's best to have zero warnings in an ideal world.

Visual studio - can't remove project configurations

I have a major problem with project configurations. Everything started when I wanted to add new solution configuration (named "Dev_WithSource") based on existing "Debug" configuration and checked "Create project configurations". For some reason project configurations were registered inside sln file, properly showing in Configuration manager, but "PropertyGroup Condition" blocks in csproj files weren't created. That resulted in "OutputPath not set ..." error.
So, I tried to repeat whole procedure. After deleting all lines mentioning "Dev_WithSource" from sln file, "Dev_WithSource" project configurations are still showing in configuration manager. I searched all csproj and sln file in my solution. Neither of them contain text "Dev_WithSource".
After all that I event tried developing add-in. I can fetch phantom configurations with project.ConfigurationManager.ConfigurationRowNames but I also can't delete them.
Am I missing something? Are those configurations stored in some other files and not csproj/sln?
Thanks.
Access the configuration manager in one of two ways:
From the menus on top: Build > Configuration Manager...
From the drop down listing your configurations on the main tool bar select Configuration Manager...
In the configuration manager dialog under Active solution configuration: choose <Edit...> from the drop down.
A dialog opens showing all the configurations for your solution. Here you can select and click the Remove button.
Right-click->Unload your project with the configurations you want to remove.
Right-click->Edit project file xml directly.
Delete the Property groups containing conditions containing the name of the platforms/configurations you wish gone.
Save and load project again. Unwanted configurations should be gone.
If a configuration seems set up right but OutPutPath is still "not set", try moving its propertygroup tag up in the xml.
Let's suppose you want to remove "Release" configuration from the entire solution and the projects. So, first you go to Tools -> Nuget Package Manager -> Package Manager Console.
Copy and past the following command in the console to remove the build from all the projects. You may want to replace "Release" with the configuration name you wish to delete.
Get-Project -All | Foreach { $_.ConfigurationMAnager.DeleteConfigurationRow("Release") }
Finally, remove the configuration solution-wise as explained by Mike Grimm's answer.
I know this is an old thread, but this was the answer for me:
In the Configuration Manager, select "Edit..." in the "Configuration" column for each project (not via the dropdown named Active solution configuration) that has configurations you want to remove.
In the dialog that pops up, mark each unwanted configuration and select "Remove".
Copied from How do I remove a project configuration in Visual Studio 2008?
You need to remove the configuration from the solution AND the project. From the Configuration Manager:
Active solution configuration > Edit > Remove
Project contexts > Configuration > Edit > Remove
I solved this with utility which parses csproj files and inserts necessary propertygroup blocks into csproj files. Old project configurations still appear in configuration manager but I gave up trying to delete them.
In my case the issue was that the solution file was not in the same folder as project file so I had to copy the nuget folder into the solution folder to resolve this issue.
In Visual Studio for MAC -
Double click your Solution > Configurations > General.
Click on your 'ConfigToRemove' in the list then Remove (Ensure you tick delete also Configurations in Solution items), then Yes.
Click OK to save your changes.
Now, right Click on Solution and Tools > Edit File.
Go to "GlobalSection(SolutionConfigurationPlatforms) = preSolution" and remove all the Configurations you no longer need otherwise they will still show up in Configuration Mappings even though there are no mappings in the project!
Save and your done.
I know I am bit Late but here is complete solution.
To remove configuration completely from solution and project property then open .sln file in any IDE as Plain text and delete all information regarding the configuration.
NOTE- don't delete GUID values and debug/release configurations
Then open .vcxproj file in XML format and delete all information regarding the configuration. This includes fundamental property for it, Platform Toolset and Assosiated property elements in XML language.
NOTE- make sure to delete end tags.
when you go back to visual studio, click replace all and you are good to go.

Transfer all ReSharper Settings between PCs

I was wondering if there is a way to copy ALL my settings from ReSharper (including the StyleCop for ReSharper settings and the keyboard bindings I have set for ReSharper) from one PC to another?
Since the export option within Resharper is only for code styles, you'll need to be a bit craftier for all settings.
From Peter Ritchie's blog...
...the settings are stored in
"%userprofile%\application
data\jetbrains\resharper\v4.0\vs9.0".
There are a couple of xml files in
there that store your settings.
Before you upgrade to the latest
build, just copy those to another
directory.
It's very likely that the format of
these files has changed since the last
build so copying the backups over the
new version could possibly make
Resharper to blow-up. So, use with
caution.
I have Resharper 4.1 so instead of "...\v4.0\vs9.0" it's actually "...\v4.1\vs9.0" (obvious, I know, but worth mentioning).
I'm not sure about StyleCop settings, but this should work for most other settings (keyboard scheme, code completion settings, etc...).
There is a R# settings manager plugin for resharper that stores all of this I think, including stylecop settings
Open Visual Studio
Go to Resharper > Manage Options
Click on Import and Export
Click on Export to File
Tick all check box
Click on OK and save the file to your desired location
To import the settings to other computer, repeat steps 1-3 and then select Import from File. You are done.
Enjoy!
You can Export/Import your ReSharper Code Style or put it on the network and share between multiple computers. To do so:
From VS Menu select ReSharper -> Options then in Option dialog select Languages/Common/Code Style Sharing.
Not sure if it's exactly what you're looking for.
StyleCop settings are not stored in the resharper plugin. they are in the stylecop directory and in an xml file (Settings.StyleCop).
I have a solution that i am using!
Skydrive and junction link magic.
I create a junction in the filesystem that point the settings to a skydrive folder.
this way i have everywhere i use skydrive the same settings!!!
On the target pc i do the opposite.
Hope this helps.
Steve Dignan's answer is probably correct for 2009 version of Resharper.
In newer versions of Resharper global for PC Resharper settings are located in:
%userprofile%\Appdata\Roaming\JetBrains\Shared\vAny\GlobalSettingsStorage.DotSettings.
Solution team-shared settings are in the solution folder called {Solution Name}.sln.DotSettings.
Solution's personal settings are in {Solution Name}.sln.DotSettings.user.
Source: https://resharper-support.jetbrains.com/hc/en-us/articles/115001216530-Where-to-find-DotSettings-files-associated-with-settings-layers
So to transfer settings between 2 PCs, copy settings file(s) for the appropriate layer(s) you want to transfer and that's it. Usually just copying global is enough.

Why is "Set as Startup" option stored in the suo file and not the sln file?

It seems like this setting should be stored in the solution file so it's shared across all users and part of source code control. Since we don't check in the suo file, each user has to set this separately which seems strange.
It is absolutely necessary that everyone can define their StartUp Project themselves, as Jon has already said. But to have a dedicated default one would be great, and as I can tell, it is possible!
If you don’t have a .suo file in your solution directory, Visual Studio picks the first project in your .sln file as the default startup project.
Close your Visual Studio and open the .sln file in your favorite text editor. Starting in line 4, you see all your projects encapsulated in Project – EndProject lines.
Cut and paste the desired default startup project to the top position.
Delete your .suo file.
Open your solution in Visual Studio. Ta daa!
In most cases, it does make sense to have a default on this.
It would be much better to accommodate a default startup project and store this in the .sln file, but which can be overridden by a developer in their .suo file. If the startup setting isn’t found in the .suo file, the default startup project in the .sln would be used.
Actually, this has been suggested on Visual Studio’s UserVoice.
Why should it be a non-user-specific preference?
If I've got a solution with 10 files in, and one developer is primarily testing/using one of those tools, why should that affect what I start up?
I think MS made the right choice on this one. The project I want to start is far from necessarily the project that other developers want to start.
I wrote a little command line utility for Windows called slnStartupProject to set the Startup Project automatically:
slnStartupProject slnFilename projectName
I personally use it to set the startup project after generating the solution with cmake that always sets a dummy ALL_BUILD project as the first project in the solution.
The source is on GitHub. Forks and feedback are welcome.
If you are using GIT, you can commit the default SUO file and then mark it as unchanged using
git update-index --assume-unchanged YourSolution.suo
It works also if you want to have more than one project in your default start group. The only disadvantage that I know about is that this command must be run by everyone who don't want to commit the SUO file.

Categories