從 .NET Core SDK 1.0 Preview 3 build 004056 開始,.NET Core 棄用 project.json,回歸 .csproj,主要原因是為了兼容 MSBuild ,詳見 Announcing .NET Core Tools MSBuild “alpha” 。
如果你安裝了 .NET Command Line Tools (1.0.0-preview3-004056) ,運行 dotnet new 不會創建 project.json 文件,取而代之的是 .csproj 文件,文件內容如下:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" /> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.0</TargetFramework> </PropertyGroup> <ItemGroup> <Compile Include="**\*.cs" /> <EmbeddedResource Include="**\*.resx" /> </ItemGroup> <ItemGroup> <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> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
dotnet restore, dotnet build, dotnet publish, dotnet run 都會使用這個 .csproj 文件,不再支持 project.json 。
用 Visual Studio for Mac 創建的 .NET Core 項目也是只有 .csproj ,沒有 project.json 。
用 Visual Studio 2017 RC 創建的 .NET Core 項目也是只有 .csproj ,沒有 project.json 。
將 project.json 轉換為 .csproj 有2種方法:
1)在 project.json 所在的項目文件夾,運行 dotnet migrate 命令。
2)用 Visual Studio 2017 RC 打開現有的 .sln ,VS2017 會自動幫您轉換(實測發現VS2017的自動轉換有些不靠譜,還是dotnet migrate命令靠譜)。
目前 Visual Studio 2015 不支持 .NET Core 的 .csproj 。
文章列表