将 msbuild 任务作为 nuget 发送 [英] Shipping msbuild task as nuget

查看:45
本文介绍了将 msbuild 任务作为 nuget 发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助.

我正在开发一个 msbuild 任务,该任务对 msbuild 执行某些操作.

I'm developing an msbuild task that performs certain actions upon msbuild.

我希望我的用户能够下载并安装 nuget 包,一旦安装了该包,构建任务将成为构建过程的一部分.

I want my users to be able to download and install a nuget package and once the package is installed the build task will be part of the build process.

我知道如何发布 nuget 包,我知道如何将自定义目标文件与 nuget 一起包含,我不知道如何在安装 nuget 时将 import 语句添加到 csproj:

I know how to release a nuget package and i know how to includes a custom targets file together with the nuget, what i don't know is how to add the import statement to the csproj upon nuget installation:

有没有办法做到这一点,还是我要求太多?

Is there a way to do so or am i asking for too much?

谢谢!吉拉德

推荐答案

文档不是最容易找到的地方,但 这里是关于在包中包含 MSBuild 道具/目标文件的文档的链接.

The docs aren't in the easiest to find place, but here's a link to the docs on including MSBuild props/targets files in your package.

基本上,您将文件放在包中 build\<tfm>\<package_id>.props 的位置.例如 build\netstandard2.0\MyPackage.props.如果您希望您的构建目标包含在所有 TFM 中,您可以使用 build\.props,但如果您的包还包含其他资产,例如 lib/contentFiles/,no-TFM"构建文件将导致asset-target fallback"失败,所以如果你的包只有 net472 库,并且 build 文件,针对 netcoreapp3.0 的项目将只获得 build 资产,没有 net472 资产.如果您的 build 文件位于 TFM 文件夹中,则 NuGet 的资产目标回退将同时选择 libbuild 资产.因此,我强烈建议大家始终使用 TFM 文件夹.

Basically, you put the file in the package in the location build\<tfm>\<package_id>.props. For example build\netstandard2.0\MyPackage.props. If you want your build targets to be included in all TFMs, you can use build\<package_id>.props, but if your package also contains other assets like lib/ or contentFiles/, the "no-TFM" build files will cause "asset-target fallback" to fail, so if your package has only net472 libs, and the build files, a project targeting netcoreapp3.0 will get only the build assets, none of the net472 assets. If your build files are in a TFM folder, then NuGet's asset target fallback will select both the lib and build assets. So, I strongly encourage everyone to always use the TFM folder.

文档需要改进,但是 解释表 列出了buildbuildTransitivebuildMultiTargeting.使用 packages.config 的项目仅使用 build 下的构建资产.当项目直接引用包时,使用 PackageReference 的项目仅使用 buildbuildMultiTargeting 资产.buildTransitive 下的资产在包被传递时而不是直接拉入时被选中.buildbuildMultiTargeting 之间的区别很复杂.如果你理解了多目标SDK风格项目中内建"和外建"的概念,那就是区别了(build是内建),否则只用build.

The docs need to be improved, but the table explaining lists build, buildTransitive, and buildMultiTargeting. Projects using packages.config only use build assets under build. Projects using PackageReference only use build and buildMultiTargeting assets when the project references the package directly. Assets under buildTransitive get selected when the package is pulled in transitively, rather than directly. The difference between build and buildMultiTargeting is complex. If you understand the concept of "inner-build" and "outer-build" in multi-targeting SDK style projects, that's the difference (build is inner-build), otherwise only use build.

我应该更新文档以获得这些信息.

I should update the docs to have this information.

这篇关于将 msbuild 任务作为 nuget 发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆