I finally have the opportunity to play around with .NET Core in Visual Studio Code on MacOSX, but obviously a lot of things are different compared to the oldschool .NET Framework/Visual Studio way.
For starters I have not had any luck finding a way to set a default namespace in my .NET Core 2.1 project.
I have tried changing the project name in the .sln file to RootNS.ProjectName
instead of the default ProjectName
, but although the project name in Solution Explorer is reflecting my change, it does not set the expected namespace when creating new classes - it seems to only follow the folder name.
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RootNS.ProjectName", "ProjectName\ProjectName.csproj", "{443D0B42-6E6C-4DC6-8E42-E90FFCEBD448}"
Am I too naive to even think this is possible?
Thanks!
Edit:
I have already tried adding the RootNamespace
element to the .csproj file like so:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>RootNS.ProjectName</RootNamespace>
</PropertyGroup>
I use Visual Studio Code on MacOSX.
Assuming this is for a C# project and assuming that you want to change the default namespace, you need to go to Project Properties, Application tab, and specify "Default Namespace". Default namespace is the namespace that Visual studio sets when you create a new class.
The root namespace is also the default namespace for C# programs.
Place your cursor in the namespace name. Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Change namespace to <folder name>.
The System namespace is the root namespace for fundamental types in . NET. This namespace includes classes that represent the base data types used by all applications, for example, Object (the root of the inheritance hierarchy), Byte, Char, Array, Int32, and String.
The answer is going to depend upon the C# plugins you happen to be using with Visual Studio. I've used the <RootNamespace>RootNS.ProjectName</RootNamespace>
in the past but it did not work on both Windows and Linux for me. I was using one of the many c# Extensions plugins. Not sure which on.
I am using VS Sharper for C# plugin now. It has a configuration file called "vssharper.json" where you can add things like
{
"namespace": "Answers.Hello"
}
That works for me in Windows and Linux. I'd try that on your Mac.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With