试图了解global.json在Visual Studio中的工作原理 [英] Trying to understand how global.json works in Visual Studio

查看:109
本文介绍了试图了解global.json在Visual Studio中的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


创建一个新项目后(例如在.net核心中),解决方案的global.json看起来像

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



并且内部创建的新项目  src  文件夹,解决方案文件夹中存在一个物理文件夹。虽然global.json出现在解决方案
Items
  visual studio中的解决方案文件夹中,没有名为solution的物理文件夹物品存在。



现在,如果我添加一个单元测试项目,它只是在解决方案文件夹中创建,它不会创建任何名为&embsp = 测试



然后我创建了一个测试文件夹,它不会出现在VS上,并且创建一个新的测试项目不会在测试物理文件夹中创建。另外,我可以在
下创建测试项目 src文件夹



如果我添加另一个新项目,新项目内部创建  src  文件夹。如果我添加任何项目(例如XMLFile),则将其添加到  解决方案项 解决方案
文件夹中。但是如果你添加测试项目,如果只是出现在解决方案文件夹下面



现在解决方案树是







和文件浏览器中的解决方案根文件夹如下所示





但是,我的问题是关于行为的差异。


  1. 为什么测试项目的行为不同
  2. 为什么测试会自动添加到global.json上?



我也注意到如果测试项目不在测试文件夹中,有时候,它没有找到xunit或nunit测试,但是它找到了MSTest测试。所以,我的观点是如何  test  在global.json
帮助我们?

解决方案

Jobayer,


欢迎来到MSDN论坛。


>>为什么测试项目的行为不同


请参阅您的说明,我想与您确认您是如何添加单元测试项目的?通常,如果我们想直接在文件夹/解决方案下添加项目,请单击
文件夹名称或项目名称,然后单击"添加"以在其下添加新项目。


>>为什么测试会自动添加到global.json上?


关于global.json文件,用于.NET Core项目以定义解决方案元数据。当
dotnet-restore
命令来恢复.NET Core项目的依赖关系。请看一下:

global.json reference
和'projects'指定构建系统在解析依赖项时应搜索项目的文件夹。"src"和" test"是在创建.net核心解决方案时默认创建的,我们也可以修改/添加文件夹到
它引用你的解决方案结构。


如果你想了解更多关于global.json的详细信息,因为我们的论坛是
讨论Visual Studio WPF / SL Designer,Visual Studio Guidance Automation Toolkit,开发人员文档和帮助系统以及Visual Studio编辑器。您可以重定向到
相应的论坛:
https://forums.asp.net/1255.aspx/1?ASP+NET+Core
并创建一个新线程以获得更专业的支持,感谢您的支持。




祝你好运,


萨拉


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?

解决方案

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


这篇关于试图了解global.json在Visual Studio中的工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆