Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How important is the global.json and src folder?

In VS 2015, when you create a new MVC 6.0 application using this approach:

File-->New-->Project-->ASP.NET Web Application-->ASP.NET 5 Preview Templates

You end up have the following file structure on disk:

  • artifacts
  • src
  • MyProject.sln
  • global.json

Instead if I decide to create a blank solution first like so:

 File-->New-->Project-->Other Project Types-->Visual Studio Solutions-->Blank Solution

And start adding a new ASP.NET Web Application project to this solution; you end up having a file structure that doesn’t have a global.json file and no src folder.

According to the documentation, the global.json file is used to configure the solution as a whole. It includes just two sections, projects and sdk by default.

The projects property designates which folders contain source code for the solution. By default the project structure places source files in a src folder, allowing build artifacts to be placed in a sibling folder, making it easier to exclude such things from source control.

The sdk property specifies the version of the DNX (.Net Execution Environment) that Visual Studio will use when opening the solution. It’s set here, rather than in project.json, to avoid scenarios where different projects within a solution are targeting different versions of the SDK.

Question 1)

As mentioned above, if I choose to first create a Blank Solution, I won’t be having a global.json file.

Is not having a global.json file impact the application’s behavior in any shape or form? For example when I deploy or the interaction with the build artifacts?

Question 2)

If it does have an impact, then should I manually be creating this global.json file?

Question 3)

As of this writing, is there a recommended approach for creating a multi-layered application in ASP.NET 5?

Should I first create the MVC project and start adding Class Libraries to the project?

Or

Should I first start by creating a Blank Solution and start adding the Class Libraries and the Web Application to the solution (knowing I won’t have global.json file nor a src folder)?

like image 470
Vlince Avatar asked Jul 22 '15 14:07

Vlince


People also ask

Do I need a global json?

For machines that have never had a . NET Core 3.0 or higher runtime or SDK installed, you need to create a global. json file and specify the exact version you want to use.

What is launchSettings json in .NET Core?

The launchSettings. json file is used to store the configuration information, which describes how to start the ASP.NET Core application, using Visual Studio. The file is used only during the development of the application using Visual Studio. It contains only those settings that required to run the application.

How do I check my current .NET Core version?

You can see both the SDK versions and runtime versions with the command dotnet --info .


2 Answers

The src, test, etc. folders allow you to group projects by type. This helps keep the solution maintainable when there are a large number of projects. Here is an example of various project types that have been proposed.

Per the ASP.NET Core Engineering Guidelines: "By default project-to-project references must be sibling folders. Using a global.json file allows a solution to specify non-standard locations to locate references."

To sum it up, if have lots of projects, you can group them by type into folders and use global.json to allow projects in one group to reference those in another.

like image 142
Edward Brey Avatar answered Sep 21 '22 05:09

Edward Brey


1) Yes, for me I also had this issue and started with blank solution. Then my projects had issues referencing each others.

2) For me it did not work without global.json. You also need to make sure the solution file points correctly to everything, like the global.json. The projects did not build and did not find each others for me otherwise.

3) To get everything working I created a mvc core project first to get the global.json file. Then I renamed the scr folder to applicationname.web. Make sure to alter the solution file accordingly so it does not point wrong. Also you should update the project.json file. This way, all thou I wanted a blank solution like you, I created a default project and then altered it to how I wanted it, that worked for me.

I will build my current app using Onion Architeture as a guideline. I see no issue doing this with core. This also means that I will build the IoC in a different project (probably named infrastructure.IoC) so that my web project does not contain references to projects containing implementations of interfaces that the web should not know about.

Also, if you still have problems, I actually got local build and reference problems because I had resharper and I turned that off, then the reference problems between projects went away and I could build successfully.

like image 33
Johan Avatar answered Sep 25 '22 05:09

Johan