visual-studio-2017 - .targets 文件在哪里,.net core 是否支持

标签 visual-studio-2017 .net-core nuget

我有一个自定义 nuget 包,其中包含 \build 文件夹中的 .targets 文件。当我将其安装到.net框架项目中时,安装后,我们可以在项目文件中看到以下导入列表:

<Import Project="..\packages\xxxx\build\xxxx.targets" Condition="Exists('..\packages\xxxx\build\xxxx.targets')" />

但是当我将其安装到 .net core 项目时,我无法在项目文件中找到此导入列表,如果 .net core 支持的话,我可以在其中找到我的 .targets 文件?

最佳答案

Where is the .targets file, and if it supported by .net core

.targets文件包含在obj文件夹下的project.assets.json文件中,您可以查看project.assets.json code> 文件,则可以得到如下代码:

  "xxxx/1.0.0.0": {
    "type": "package",
    "build": {
      "build/xxxx.targets": {}
    }
  },

并且这个.targets文件也受到.net core项目的支持。作为测试,我在 nuget 包中创建了一个测试 .targets 文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Test" AfterTargets="Build">
    <Message Text="This is Test Sample!"></Message>
  </Target> 
</Project>

将此 nuget 包安装到 .net core 项目后,然后构建该项目,我可以获得带有消息“This is Test Sample!”的输出窗口

关于visual-studio-2017 - .targets 文件在哪里,.net core 是否支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50869803/

相关文章:

c# - BrowserLink 工具不适用于 ASP.NET Core 2.1?

.net-core - .NET Core 3.1 Websocket 错误 : The specified network name is no longer available

azure-devops - 如何为 Nuget Artifact 配置 Azure Devops Pipeline 包名称

visual-studio - NuGet 3.5/Visual Studio 2015 - 更改包缓存位置

c# - 替换 .NET 6/.NET Core 中过时的 Assembly.CodeBase

c# - 强制 Nuget 包使用特定版本的子依赖项?

c# - 越来越奇怪 BadImageFormatException : Cannot load a reference assembly for execution

c++ - x64 位的 C++/CLI DLL 和 Exe 应用程序崩溃

azure - 使用 Arm 模板创建资源组并部署资源并从 Visual Studio 进行部署

.net-core - 从 EntityFrameworkCore 2.1 升级并破坏代码时添加的 SQL 'AS' 关键字