【问题标题】:Visual Studio 2017 csproj .NET CORE netstandard2.0 not buildingVisual Studio 2017 csproj .NET CORE netstandard2.0 未构建
【发布时间】:2017-08-08 10:33:58
【问题描述】:

我刚刚安装了 VS2017,并将我的 .NET 核心项目从 project.json 格式迁移到新的 csproj 格式。我想要的是针对多个框架,这样我就可以使用更小的占用空间来构建框架依赖部署和自包含部署。我按照 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 publish -c Release -r win10-x64 时,我仍然会得到 FDD 输出,而不是独立的可执行文件。我觉得使用 json 文件更容易......我做错了什么?

【问题讨论】:

  • "win10-x64": {} 后面少了一个逗号

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


【解决方案1】:

当 Nuget 包未恢复时,我收到了相同的错误消息。您是否确保软件包已正确还原,并且运行“dotnet restore”时不会出现错误?

【讨论】:

  • 所以,我觉得自己真的很愚蠢,因为我本可以发誓我这样做了,但是今天早上再次尝试时,看起来就是这样。谢谢!
  • 太棒了!有时只需要两只额外的眼睛!
猜你喜欢
  • 2017-08-12
  • 1970-01-01
  • 1970-01-01
  • 2018-06-02
  • 1970-01-01
  • 1970-01-01
  • 2018-09-13
  • 2018-06-21
  • 2018-08-18
相关资源
最近更新 更多