Share via


Trying to understand how global.json works in Visual Studio

Question

Tuesday, January 31, 2017 1:23 PM

After creating a new project (example is in .net core) the global.json of the solution looks like that

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003131"
  }
}

And the new project created inside src folder and there is a physical folder exists inside the solution folder. Although the global.json appears inside Solution Items solution folder in the visual studio, no physical folder named solution items exists.

Now if i add a unittest project it creates just inside the solution folder, it does not create any Solution Folder or Physical Folder named test.

Then i created a test folder it does not appear on VS and creating a new test project does not create within the test physical folder. In addition, I can create test project underneath src Folder

If i add an another new project the new project created inside src folder. If I add any item (e.g. XMLFile) it add it within the Solution Items solution folder. But if you add test project if just appears underneath solution folder

Now the solution tree is



and the solution root folder in file explorer looks like below

However, my question is about the discrepancies of the behaviours.

  1. Why the behaviour is different for test projects
  2. Why is the test added on global.json automatically?

I have also noticed that if the test project is not inside the test folder, sometimes, it does not find xunit or nunit tests, but it finds the MSTest tests. So, my point is how the test in global.json helping us?

All replies (1)

Thursday, February 2, 2017 8:24 AM

Hi Jobayer,

Welcome to the MSDN forum.

>>Why the behaviour is different for test projects

Refer to your description, I want to confirm with you how did you added the unit test project? Usually, if we want to add a project directly under the folder/solution, click the folder name or project name and click ‘Add’ to add a new project under it.

>> Why is the test added on global.json automatically?

About global.json file, is used on .NET Core projects to define the solution metadata. This file is used when the dotnet-restore command is invoked to restore the dependencies of a .NET Core project. Please have a look at this: global.json reference and ‘projects’ Specifies which folders the build system should search for projects when resolving dependencies. The “src” and “test” is default created when you create the .net core solution and we can also modify/add the folder into it refer your solution structure.

If you want to know more detail information about the global.json, since our forum is to discuss Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor. You can redirect to the appropriate forum: https://forums.asp.net/1255.aspx/1?ASP+NET+Core and create a new thread for a more professional support, thank you for your support.

Best regards,

Sara

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.