试图了解global.json在Visual Studio中的工作原理

编程入门 行业动态 更新时间:2024-10-22 13:42:58
本文介绍了试图了解global.json在Visual Studio中的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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

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

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

现在解决方案树是

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

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

  • 为什么测试项目的行为不同
  • 为什么测试会自动添加到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"是在创建核心解决方案时默认创建的,我们也可以修改/添加文件夹到它引用你的解决方案结构。

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

    祝你好运,

    萨拉

    After creating a new project (example is in 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 insidesrcfolder and there is a physical folder exists inside the solution folder. Although the global.json appears insideSolution Itemssolution 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 namedtest.

    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 insidesrcfolder. If I add any item (e.g. XMLFile) it add it within theSolution Itemssolution 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.

  • Why the behaviour is different for test projects
  • 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 thetestin 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 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: forums.asp/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中的工作原理

    本文发布于:2023-11-14 09:23:21,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1586835.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:工作原理   json   global   Studio   Visual

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!