Bye-Bye Project.json and .xproj and welcome back .csproj

I personally liked Project.json idea to manage dependencies, framework and managing pre, post build and publish events as JSON is far easy to handle than XML. Sadly, it is going to become history now. To see this change in action, you have to download .NET Core nightly build from here. At the time of writing this post, this change was available in the nightly build only. So download the .NET Core installer based on your platform and install it. If you are new to .NET Core, then read How to Install ASP.NET Core And Create Your First Application

Once the installation is over, go to command prompt and run following command to ensure the latest version of tooling is installed or not.

dotnet --version

And you should see following.

The dotnet tooling version number may be different on your system, as this is a nightly build and likely to be replaced with new build. So in my system, the tooling version is “1.0.0-preview4-004175”. Please keep in mind, this is a nightly build and there would be issues. Let’s create an .NET Core application.

dotnet new
dotnet restore
dotnet run

So the application is running successfully. And following is the screenshot of the folder.

After executing above command, visit the folder where this ASP.NET Core Web application is created. And you will find there is no Project.json and .xproj.

Now, restore the packages via dotnet restore. But there is an error “Unable to resolve ‘Microsoft.NET.Sdk.Web (>= 1.0.0-alpha-20161117-1-119)’ for ‘.NETCoreApp,Version=v1.0′”> while restoring the packages.

The error is related with Microsoft.NET.Sdk.Web package which is not getting restored successfully. To fix this error, open the .csproj file. As you can see, .csproj now contains a list of all the dependencies and framework version like project.json. To fix the error, look for Microsoft.NET.Sdk.Web. And update package version to 1.0.0-* from 1.0.0-alpha-20161117-1-119 and save it.

Let’s open it again. And there comes one more error “The attribute “Version” in element is unrecognized.”. I couldn’t find a fix and honestly, I didn’t put much effort to fix it as it’s a nightly build and contains some bugs.

Now, let’s try to create a new application from VS 2015 itself. And following error is coming as soon as you hit ok after selecting web application option from the selection dialog box.

So it seems that there are some issues with the nightly build. And let’s not worry about them as these will be addressed when the final release will be made.

What about old projects?

When this change was announced, it was also mentioned that this migration will be done automatically via VS when old projects (with .xproj) will be opened. But for now, it is not happening (since it’s a nightly build). But is there any way to migrate it now?

Well, the answer is Yes. I posted about Entity Framework Core InMemory provider with ASP.NET Core and let’s migrate it to new .csproj. dotnet tooling support migrate command which migrates a Preview 2 .NET Core project to Preview 3 .NET Core project. You can get more information about dotnet migrate from here.

So let’s do the migration now. Open command prompt and get to the location where the old project resides and execute dotnet migrate command. And got an error saying “no executable found matching command dotnet-migrate”. I tried executing at parent folder also but got the same error.

To fix above error, I followed these steps.

Open global.json in notepad, and update the SDK version to 1.0.0-preview4-004175 (this is the version that’s installed on my syetem).

Go back to command prompt, and execute dotnet migrate command again. And this time, it works.

Execute dotnet restore to restore packages. And once that is done, you will find project.json and .xproj files are now gone and .csproj file is present. All the dependencies are now part of .csproj.

Running dotnet run should run the application.

Summary

Though Project.json was a welcome change the experience is better than traditional .csproj. Since the announcement of ASP.NET Core (aka ASP.NET 5), things have changed as the framework is becoming more and more mature and probably based on the community feedback. So bye-bye Project.json and .xproj, let’s celebrate the rebirth of .csproj.

Thank you for reading. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in the comments section.

PS: If you found this content valuable and want to return the favour, then