23

I did not find project.json in visual studio 2017 RC. Has this been removed in this version or am i missing something ? How do they store list of dependencies now if it is removed ?

aspxsushil
  • 514
  • 1
  • 5
  • 16

3 Answers3

45

Going forward, .Net Core is going to be based on msbuild, which means that it's going to use *.csproj instead of project.json. Package references are now also stored in the *.csproj file.

For more information, read Announcing .NET Core Tools MSBuild “alpha” on the .NET Blog and High level overview of changes in CLI Preview 3 in .NET Documentation.

For example, if you had this in your project.json:

"dependencies": {
  "Microsoft.NETCore.App": {
    "type": "platform",
    "version": "1.0.0"
  },
  "Newtonsoft.Json": "9.0.1"
}

You will now have *.csproj containing:

<PackageReference Include="Microsoft.NETCore.App">
  <Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
  <Version>1.0.0-alpha-20161104-2</Version>
  <PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
  <Version>9.0.1</Version>
</PackageReference>
svick
  • 236,525
  • 50
  • 385
  • 514
  • 4
    I'm sure there is a valid reason for switching from project.json to *.csproj, but from where I'm sitting... project.json is about 10 times easier to comprehend at a glance from a coding perspective... – Kevin Francis Apr 05 '17 at 16:29
  • 2
    @KevinFrancis Keep in mind that the csproj fragment I showed here is outdated. You no longer reference `Microsoft.NETCore.App`, the SDK is just a single attribute on the root element and package versions can be specified using an attribute. In my opinion, even if you dislike the XML syntax, the increased power and unification with all other project types is worth it. – svick Apr 05 '17 at 16:40
  • @svick Do you know where I specify that I want to create an exe-file out of my console app after this change? Before, you could do this in `project.json`. Right now, compiling my console app only creates a DLL in the /Debug folder. – silkfire May 08 '17 at 00:20
  • @silkfire If you want to do a self-contained deployment, then you need to specify `` in your csproj and then use `dotnet publish` for that RID. – svick May 08 '17 at 00:25
  • @svick Isn't it a bit hacky to have to change the `csproj` externally? – silkfire May 08 '17 at 05:09
  • @silkfire I don't think so. 1. I believe it's the only choice here. 2. There was a lot of effort spent on making csprojs manually editable (including making the files simpler and being able to open the csproj in VS without unloading the project). – svick May 08 '17 at 12:15
3

Refer Given Link

https://learn.microsoft.com/en-us/dotnet/core/tools/project-json-to-csproj

Project.json

{
  "buildOptions": {
    "warningsAsErrors": true,
    "nowarn": ["CS0168", "CS0219"],
    "xmlDoc": true,
    "preserveCompilationContext": true,
    "outputName": "Different.AssemblyName",
    "debugType": "portable",
    "allowUnsafe": true,
    "define": ["TEST", "OTHERCONDITION"]
  }
}

Solution->Right Click ->Edit Project.csporj

<PropertyGroup>
  <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  <NoWarn>$(NoWarn);CS0168;CS0219</NoWarn>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
  <PreserveCompilationContext>true</PreserveCompilationContext>
  <AssemblyName>Different.AssemblyName</AssemblyName>
  <DebugType>portable</DebugType>
  <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  <DefineConstants>$(DefineConstants);TEST;OTHERCONDITION</DefineConstants>
</PropertyGroup>
Muhamed Shafeeq
  • 1,194
  • 1
  • 9
  • 15
3

In Solution Explorer:

  1. Right Click on the Project
  2. Select Edit (YourProjectNameHere).csproj

A window should appear allowing you to view the XML version of the .csproj. The dependencies will be listed here under the PackageReference description.

Simon
  • 482
  • 1
  • 8
  • 26