【问题标题】:How to specify ASP.NET Core target framework imports in .csproj file (instead of project.json)?如何在 .csproj 文件(而不是 project.json)中指定 ASP.NET Core 目标框架导入?
【发布时间】:2016-11-19 20:11:32
【问题描述】:

我正在构建一个 ASP.NET Core 应用程序,并尝试安装 Azure 存储包。

从 Azure 存储 github 页面,它说我需要将以下内容放在我的 project.json 文件中 - 但由于这是使用最新的 ASP.NET Core 版本,我们没有 project.json 文件,只是.csproj 文件。

"imports": [
    "dnxcore50",
    "portable-net451+win8"
  ]

有没有办法在 .csproj 文件中执行此操作?我想这个地方可能在这附近:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
  </PropertyGroup>

非常感谢!

【问题讨论】:

  • project.json/.csproj 与 ASP.NET Core 无关,它取决于安装的 VS 工具的版本,新的 csproj 结构仅适用于 VS 2017(工具的预览版 4)。 VS2015 依然使用preview2/2-1
  • 对 - 我在 Mac 上使用 Visual Studio 和它提供的 ASP.NET Core 模板。

标签: asp.net .net azure asp.net-core


【解决方案1】:

将我的一个项目迁移到新模型后,它生成了以下内容:

<PropertyGroup>
    <TargetFramework>netcoreapp1.6</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>TestApp</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.6' ">$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
</PropertyGroup>

尝试以类似的方式添加 dnxcore50 和portable-net451+win8,如下所示:

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">$(PackageTargetFallback);dnxcore50;portable-net451+win8</PackageTargetFallback>
</PropertyGroup>

【讨论】:

  • 这是否增加了对 .NET 451 的依赖,如果增加了,它将不再能够在 Linux 上运行吗?谢谢。
  • 我在 Mac 上做这个,所以我认为在 Linux 上也可以。
  • 我的项目不知何故从netcoreapp1.1 切换到net452,导致启动时出现错误图像运行时错误。恢复更改解决了这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-02
  • 2015-10-19
  • 2017-04-13
  • 2018-08-30
相关资源
最近更新 更多