Hi there,
Hopefully, someone can help me with this.
I see that in the latest updates for the Omnisharp Extension for VS Code that there is now support for a global omnisharp.json file so I can specify settings for C# Code formatting.
Added support for global omnisharp.json file (omnisharp-roslyn#717, PR: omnisharp-roslyn#809) (Contributed by @filipw)
This file can appear in one of the following locations:
Windows: %APPDATA%\OmniSharp\omnisharp.json
macOS/Linus: ~/.omnisharp/omnisharp.json
However when I go to that location on my Mac I don't see a .omnisharp hidden folder anywhere amongst the other ones. I'm not sure if I'm just missing something here. I'd really love to get this working so formatting in VS Code would be much less of a pain! :)
Have a read of this blog post by @filipw https://www.strathweb.com/2017/01/c-code-formatting-settings-in-vs-code-and-omnisharp/
I actually just came across this shortly after posting. I suppose the part I'm a bit confused about is this.
4) An omnisharp.json file located in the working directory which OmniSharp has been pointed at
How do I find out where Omnisharp is being pointed at?
That's the folder your code is in.
Ahh okay. So there should be a hidden folder in there with an omnisharp.json file I can modify? But does that mean the setting is different on a per project basis?
Sorry, I wasn't very clear as I was on mobile earlier.
If you want it to be for everything, have a look at: ~/.vscode/extensions/ms-vscode.csharp-1.x.x/bin/omnisharp
Where 1.x.x is the version of Omnisharp/C# extension for VS Code that you have installed.
You'll need to create your own omnisharp.json file if one doesn't already exist there.
If you want to do it on a per-project basis, you'll have to create an omnisharp.json file in your source folder.
As per Filip's blog post:
1) The built-in config.json – which is located in the OmniSharp folder inside the C# extension folder itself (for example, on a Mac that’s ~/.vscode/extensions/ms-vscode.csharp-1.6.0/bin/omnisharp.).
If the file doesn’t exist, you can simply create it.
4) An omnisharp.json file located in the working directory which OmniSharp has been pointed at
The blog post was written before the latest round of updates to OmniSharp 😃
If you want it to be for everything, have a look at: ~/.vscode/extensions/ms-vscode.csharp-1.x.x/bin/omnisharp
Where 1.x.x is the version of Omnisharp/C# extension for VS Code that you have installed.You'll need to create your own omnisharp.json file if one doesn't already exist there.
Sorry - this is not accurate. If you want to configure OmniSharp from the place it's installed, the configuration file is called config.json not omnisharp.json.
However, doing this is not recommended.
Since the latest version of OmniSharp, OmniSharp has a global configuration under:
Windows: %APPDATA%\OmniSharp\omnisharp.json
macOS/Linux: ~/.omnisharp/omnisharp.json
The global folder is implictly created by OmniSharp at startup - if it doesn't exist on your machine it likely means some permission issue prevented it from being created (also the . folders are normally hidden so make sure to check that). Anyway, if the folder is not there, you can always just manually create .omnisharp folder and manually add omnisharp.json there - it's going to be picked up by OmniSharp at runtime.
the usage of this global configuration folder means that adding any configuration setting there, applies to all projects on a user's machine. This global config can be overridden on a local basis, by adding an omnisharp.json file to the root of the folder your code is located in (mind you that local override file should no longer be placed in .omnisharp folder, just directly at root of your source code).
BTW I should update the wiki here https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options with this information.
Hope this clears things up.
Thanks filipw for the post. I definitely am able to see hidden folders on my mac as I can see the other ones in the /~ path. So I was still unable to find the .omnisharp folder and I followed your steps and created me own.
So now if I open finder and hit CMD + SHIFT + G and type ~/.omnisharp/omnisharp.json it takes me directly to the folder I manually created.
The contents of the JSON file is as posted on your blog with my own custom alterations for my formatting options.
{
"FormattingOptions": {
"NewLine": "\n",
"UseTabs": false,
"TabSize": 4,
"IndentationSize": 4,
"SpacingAfterMethodDeclarationName": false,
"SpaceWithinMethodDeclarationParenthesis": false,
"SpaceBetweenEmptyMethodDeclarationParentheses": false,
"SpaceAfterMethodCallName": false,
"SpaceWithinMethodCallParentheses": false,
"SpaceBetweenEmptyMethodCallParentheses": false,
"SpaceAfterControlFlowStatementKeyword": true,
"SpaceWithinExpressionParentheses": false,
"SpaceWithinCastParentheses": false,
"SpaceWithinOtherParentheses": false,
"SpaceAfterCast": false,
"SpacesIgnoreAroundVariableDeclaration": false,
"SpaceBeforeOpenSquareBracket": false,
"SpaceBetweenEmptySquareBrackets": false,
"SpaceWithinSquareBrackets": false,
"SpaceAfterColonInBaseTypeDeclaration": true,
"SpaceAfterComma": true,
"SpaceAfterDot": false,
"SpaceAfterSemicolonsInForStatement": true,
"SpaceBeforeColonInBaseTypeDeclaration": true,
"SpaceBeforeComma": false,
"SpaceBeforeDot": false,
"SpaceBeforeSemicolonsInForStatement": false,
"SpacingAroundBinaryOperator": "single",
"IndentBraces": false,
"IndentBlock": true,
"IndentSwitchSection": true,
"IndentSwitchCaseSection": true,
"LabelPositioning": "oneLess",
"WrappingPreserveSingleLine": true,
"WrappingKeepStatementsOnSingleLine": true,
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInAccessors": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInObjectCollectionArrayInitializers": false,
"NewLinesForBracesInLambdaExpressionBody": false,
"NewLineForElse": true,
"NewLineForCatch": true,
"NewLineForFinally": true,
"NewLineForMembersInObjectInit": true,
"NewLineForMembersInAnonymousTypes": true,
"NewLineForClausesInQuery": true
}
}
Also to know as a side note, on line 45 of your paste there is a missing comma. No big deal, just might haunt someone if they don't see it right away. "NewLinesForBracesInObjectCollectionArrayInitializers": true
The changes I made are particular to the braces section. I've set all their flags to false so that my code when formatted looks like this
if (foo) {
}
as opposed to
if (foo)
{
}
However, when I right click in Visual Studio Code and hit Format Document, nothing happens. It still formats the old way and doesn't seem to register the settings I made. I restarted, VS Code and Unity. I even hit CMD + SHIFT + P in VS Code and Restarted Omnisharp. I also noticed this flag in the VS Code user settings
// Specifes whether OmniSharp should use VS Code editor settings for C# code formatting (use of tabs, indentation size).
"omnisharp.useEditorFormattingSettings": false
It was defaulted to true, so I tried setting it to false and still no luck. I have no idea what it is... but I'd love to get it working. I appreciate all the help going forward.
Which version of VS Code Extension are you using?
I can't reproduce this behavior on my Mac with the latest version so if you are on a latest, perhaps it's a permission problem, with omnisharp not being able to access the global file?
This is how it behaves for me when I added a global file you just posted:

omnisharp.useEditorFormattingSettings only affects line feeds and indentation size so that should make any difference.
Finally, you can also set "omnisharp.loggingLevel": "debug" and post all the output from the Omnisharp Log (shift + CMD + u) here
Currently running version 1.9.0 of C# extension in VS Code.
This is the current log I get on start up from VS Code.
[INFO] Starting OmniSharp at '/Users/roccob/Desktop/Research Projects/Test Logger/TestLogger/TestLogger.sln'...
[INFO] Started OmniSharp from '/Users/roccob/.vscode/extensions/ms-vscode.omnisharp-0.3.3/bin/omnisharp' with process id 61199...
[INFORMATION:OmniSharp.Startup] Omnisharp server running using stdio at location '/Users/roccob/Desktop/Research Projects/Test Logger/TestLogger' on host 61115.
[INFORMATION:OmniSharp.MSBuild.MSBuildProjectSystem] Detecting projects in '/Users/roccob/Desktop/Research Projects/Test Logger/TestLogger/TestLogger.sln'.
[INFORMATION:OmniSharp.MSBuild.MSBuildProjectSystem] Loading project from '/Users/roccob/Desktop/Research Projects/Test Logger/TestLogger/Assembly-CSharp.csproj'.
[ERROR:OmniSharp.Dnx.DnxPaths] The specified runtime path 'default' does not exist. Searched locations /Users/roccob/.dnx/runtimes/dnx-mono.default
/Users/roccob/.dnx/runtimes/kre-mono.default
/Users/roccob/.dnx/packages/KRE-Mono.default
/Users/roccob/.k/runtimes/dnx-mono.default
/Users/roccob/.k/runtimes/kre-mono.default
/Users/roccob/.k/packages/KRE-Mono.default
/Users/roccob/.kre/runtimes/dnx-mono.default
/Users/roccob/.kre/runtimes/kre-mono.default
/Users/roccob/.kre/packages/KRE-Mono.default.
Visit https://github.com/aspnet/Home for an installation guide.
[INFORMATION:OmniSharp.Dnx.DnxProjectSystem] Scanning '/Users/roccob/Desktop/Research Projects/Test Logger/TestLogger' for DNX projects
[INFORMATION:OmniSharp.Dnx.DnxProjectSystem] No project.json based projects found
[INFORMATION:OmniSharp.ScriptCs.ScriptCsProjectSystem] Detecting CSX files in '/Users/roccob/Desktop/Research Projects/Test Logger/TestLogger'.
[INFORMATION:OmniSharp.ScriptCs.ScriptCsProjectSystem] Could not find any CSX files
[INFORMATION:OmniSharp.Startup] Solution has finished loading
[INFORMATION:OmniSharp.Middleware.LoggingMiddleware] /v2/getcodeactions: 200 1464ms
Edit: The GIF you posted is exactly what I would expect my changes to do.
@roccoreli your log shows you are running version 0.3.3 not 1.9.0, which is very, very old 😃
it would be best to uninstall it, then go to /Users/roccob/.vscode/extensions/ and delete all ms-vscode.omnisharp-* folders and then reinstall the extension again.
I had a feeling that line would be an issue when I was reading the log before sending it here. But when I went to that location I also saw this folder ms-vscode.csharp-1.9.0 so I assumed the extension was that folder and perhaps Omnisharp was just using different semantic versioning.
Regardless I have followed the steps above to success!! Finally! It's most definitely picking up my omnisharp.json file globally after running a test on multiple projects. I wonder why I even had .vscode/extensions/ms-vscode.omnisharp-0.3.3 in my folder structure. I know I've been using VS Code since I believe when it was Beta so perhaps could it be left over files that were not cleaned up properly during an update? Also, makes me wonder about all features I was missing out on with this old version. 😛
Thanks a lot for all the help @filipw! To anyone that comes across this from a Google search, I hope this helps you out! Also @filipw, I know you mentioned that your old blog post is out of date and that it's on your list of todos. I'm looking forward to seeing an updated post, perhaps even outlining this as a potential problem.
great to hear - thanks 🌟
I promise to update the docs 😇
Most helpful comment
The blog post was written before the latest round of updates to OmniSharp 😃
Sorry - this is not accurate. If you want to configure OmniSharp from the place it's installed, the configuration file is called
config.jsonnotomnisharp.json.However, doing this is not recommended.
Since the latest version of OmniSharp, OmniSharp has a global configuration under:
The global folder is implictly created by OmniSharp at startup - if it doesn't exist on your machine it likely means some permission issue prevented it from being created (also the
.folders are normally hidden so make sure to check that). Anyway, if the folder is not there, you can always just manually create.omnisharpfolder and manually addomnisharp.jsonthere - it's going to be picked up by OmniSharp at runtime.the usage of this global configuration folder means that adding any configuration setting there, applies to all projects on a user's machine. This global config can be overridden on a local basis, by adding an
omnisharp.jsonfile to the root of the folder your code is located in (mind you that local override file should no longer be placed in.omnisharpfolder, just directly at root of your source code).BTW I should update the wiki here https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options with this information.
Hope this clears things up.