Visual Studio 2017 csproj .NET CORE netstandard2.0无法构建

时间:2017-03-17 01:48:58

标签: visual-studio-2017 .net-core .net-standard

我刚刚安装了VS2017并将我的.NET核心项目从project.json格式单向迁移到新的csproj格式。我想要的是针对多个框架,以便我可以使用更小的占用空间构建框架Depedenent部署和自包含部署。我按照MS文档上的说明进行操作,但是当我在TargetFrameworks中包含netstandard1.6或netstandard2.0时,当我尝试构建项目时,我得到了大量的Predefined type System.Object is not definedThe type of namespace System could not be found等等。 。这在使用project.json文件时有效。我的csproj是

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <VersionPrefix>1.0.0.0</VersionPrefix>
    <TargetFrameworks>netcoreapp1.2;netstandard2.0</TargetFrameworks>
    <AssemblyName>App</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>App</PackageId>
    <RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.2' ">1.1.1</RuntimeFrameworkVersion>-->
    <NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard2.0' ">1.6.1</NetStandardImplicitPackageVersion>
    <RuntimeIdentifiers>win10-x64;android.21;android21-arm64;osx.10.12;rhel7.4;centos.7-x64;debian8-x64;ubuntu16.10-x64;fedora.26-x64;opensuse.42.1-x64</RuntimeIdentifiers>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute
  </PropertyGroup>

  <ItemGroup>
    <None Remove="App.csproj.vspscc" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
    <PackageReference Include="System.Threading.Thread" Version="4.3.0" />
    <PackageReference Include="Microsoft.NETCore.Runtime.CoreCLR" Version="1.1.0" />
  </ItemGroup>

</Project>

我原来的project.json

{
  "version": "1.0.0.0",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "frameworks": {
    "netcoreapp1.2": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      }
    },
    "netstandard2.0": {
      "dependencies": {
        "NETStandard.Library": {
          "version": "1.6.1"
        },
        "System.Threading.Thread": "4.3.0",
        "Microsoft.NETCore.Runtime.CoreCLR": "1.1.0"
      }
    }
  },

  "runtimes": {
    "win10-x64": {}
    "ubuntu.16.10-x64": {},
    "centos.7-x64": {},
    "debian.8-x64": {},
    "fedora.24-x64": {},
    "opensuse.42.1-x64": {},
    "osx10.12-x64" : {}
  }
}

不确定问题是什么。我试图做一些不受支持的事情吗?如果我只有netcoreapp1.2,当我做一个dotnet发布时-c Release -r win10-x64我仍然得到一个FDD输出,而不是一个独立的可执行文件。我觉得这对json文件来说更容易......我做错了什么?

1 个答案:

答案 0 :(得分:3)

当Nuget-packages未恢复时,我收到了相同的错误消息。您是否确保正确恢复了软件包,并且在运行“dotnet restore”时没有出现错误?