我正在try 创建一个只包含MSBuild *.targets文件的nuget包.我可以创建一个C#类库并添加我的目标文件,但我不需要C#构建过程的开销. 有没有一种方法可以编写一个只包含静态内容或构建文件的nuget包?
我看到的答案建议只使用一个原始的nuspec文件,并使用nuget pack
来创建该包.如果可能的话,我想使用dotnet pack
,但它似乎不直接支持nuspec文件.有人知道这是否可能吗?
我正在try 创建一个只包含MSBuild *.targets文件的nuget包.我可以创建一个C#类库并添加我的目标文件,但我不需要C#构建过程的开销. 有没有一种方法可以编写一个只包含静态内容或构建文件的nuget包?
我看到的答案建议只使用一个原始的nuspec文件,并使用nuget pack
来创建该包.如果可能的话,我想使用dotnet pack
,但它似乎不直接支持nuspec文件.有人知道这是否可能吗?
这page个列出了在各种(非典型)构建场景中使用的目标.Microsoft.Build.NoTargets
...
支持不编译程序集的实用工具项目.
听起来正是我想要的. 如果你看一下这个page,它提供了关于这个项目Sdk到底做了什么的更多细节,基本上就是把files @(FilesToCopy)复制到$(OutDir)目录.
我不是真的想那样,但是...我创建了一个项目my-project,文件 struct 如下.
my-project # base project folder
|-- PackageLayout
| |-- buildTransitive
| | |-- my-project.props
| | |-- my-project.targets
| |-- icon.png
| |-- README.md
|-- my-project.msbuildproj
PackageLayout目录是我想要的Nuget包中的文件和布局.My-project t.msBuildproj文件是我定义所有包元数据、包ID、包版本等的位置.
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.Build.NoTargets/3.7.56">
<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<!-- Don't warn about no binaries, there aren't supposed to be any -->
<NoWarn>NU5128</NoWarn>
</PropertyGroup>
<PropertyGroup>
<!-- Package metadata -->
<PackageId>my-project</PackageId>
<PackageVersion>1.0.0</PackageVersion>
<DevelopmentDependency>true</DevelopmentDependency>
<IsTool>true</IsTool>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<!--
* Display project root files in the project : `Include="*"`
* But don't include them in the nuget package : `Pack="false"`
* Exclude the msbuildproj file as it is displayed
at the project level : `Exclude="$(MSBuildProjectFile)"`
-->
<None Include="*" Pack="false" Exclude="$(MSBuildProjectFile)"/>
</ItemGroup>
<ItemGroup>
<!--
Include everything in the PackageLayout directory in the package
and maintain the same directory structure (but from the package
root)
-->
<None Include="PackageLayout\**\*" Pack="true" PackagePath="\" />
<!--
Anything in buildTransitive directory, also pack in the build directory
for backwards compatability.
https://github.com/NuGet/Home/wiki/Allow-package%2d%2dauthors-to-define-build-assets-transitive-behavior
-->
<None Include="PackageLayout\buildTransitive\**\*" Pack="true" PackagePath="build\" />
</ItemGroup>
</Project>
如果我在这个项目上运行dotnet build
,它会在$(OutDir)中生成my-project.1.0.0.nupkg
,并带有正确的icon.png、readme和targets/props文件.