0

When I use Visual Studio for Mac to create a web project with .Net core 1.1, there is no project.json in my project. Is there any mistake when I create this project?

Community
  • 1
  • 1
  • [link](https://www.stevejgordon.co.uk/project-json-replaced-by-csproj)ok, looks like they changed project.json into .csproj, but there is an new problem ,when i use command to init my database under my project dic, then it throw – Ivan Barrios Oct 19 '17 at 08:36
  • 2
    You need to add a tool reference for the EF command line tools in the project – Panagiotis Kanavos Oct 19 '17 at 11:04

2 Answers2

1

project.json is deprecated and was never supported outside preview .NET Core tooling in VS 2015. The new tooling uses csproj files and can be used in VS 2017 and VS for Mac (and others like VSCode, Rider, …).

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
1

Project.json was never released in production. It was replaced by a new, vastly simplified MSBuild project format before .NET Core was released. The new format works a lot like the project.json format - it supports globbing, package references and compiles all *.cs* files found in a folder. You don't need to define dependent packages in the project file any more, you can specify *one* root package and all dependencies will be added when you executedotnet restore`

.NET Core allows you to add commandlets that appear as commands to the .NET CLI. dotnet watch executes the dotnet-watch executable. dotnet ef searches for and executes the dotnet-ef executable.

You have to add an option to the MSBuild project that installs the tool in the first place with the <DotNetCliToolReference> element. After that, dotnet restore will install the tool just like any other package.

This is described in .NET Core Command Line Tools for EF Core.

The MSBuild project file should look like this :

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" PrivateAssets="All" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
  </ItemGroup>
</Project>

This file is enough to build your project and execute ef commands from the command line, since all *.cs files will be compiled by default

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • Thanks, dotnet-ef command was running successful after i edit .csporj file add DotNetCliToolReference node ,also i changed version for Microsoft.EntityFrameworkCore.Tools.DotNet, now it works good – Ivan Barrios Oct 20 '17 at 00:18