为了实现这一点,您应该创建一个<package_id>.props 文件,该文件可以根据需要将这些文件复制到目标路径中。
1) 在您的 MyPlugin 库项目中,您应该在 Build 文件夹下创建一个名为 <package_id>.props 的文件。
然后将这些内容添加到该新文件中:
<Project>
<Target Name="CopyToFolder" BeforeTargets="Build">
<ItemGroup>
<Files Include="$(MSBuildThisFileDirectory)..\File\*.*"></Files>
</ItemGroup>
<Copy SourceFiles="@(Files)" DestinationFolder="$(ProjectDir)bin\Plugin"></Copy>
</Target>
</Project>
2) 在您的MyPlugin.csproj 文件中添加这些节点:
<ItemGroup>
<None Include="xxx\MyPlugin.dll(the path of MyPlugin.dll in your project)" Pack="true" PackagePath="File"></None>
<None Include="xxx\MyPlugin.config(the path of MyPlugin.dll in your project)" Pack="true" PackagePath="File"></None>
<None Include="Build\MyPlugin.props" Pack="true" PackagePath="build"></None>
</ItemGroup>
3)点击Pack菜单重新打包MyPlugin项目。而且在安装这个新版本的nuget包之前,应该先clean nuget caches或者删除C:\Users\xxx(current user)\.nuget\packages下的所有缓存文件。
除了,还有a similar thread you can refer to。
================================================ ====
更新 1
关于第 1 步的说明:
.props 文件必须命名为您的package_id,这样它才能在 nuget nupkg 文件上工作。请查看我在上面提供的链接。
举个例子,如果你的nuget包命名为MyPlugin.1.0.0.nupkg,那么props文件应该命名为MyPlugin.props文件。目标的建议是将nupkg的File文件夹中的文件复制到目标主项目的bin\Plugin文件夹中。
关于第 2 步的说明:
这些步骤将您的 MyPlugin 项目文件的内容打包到 nupkg 中。
因此,如果您的 MyPlugin.config 位于 MyPlugin 项目的 bin\Release 文件夹下,您应该使用:
<None Include="bin\Release\netstandard2.0\MyPlugin.config(the path of MyPlugin.dll in your project)" Pack="true" PackagePath="File"></None>
您应该确保bin\Release\netstandard2.0\MyPlugin.config是正确的,并且由于它的相对路径(与csproj文件的路径比较),您可以找到该文件。
PackagePath="File" 表示应该将MyPlugin.config 文件打包到nupkg 的File 文件夹中。
<None Include="Build\MyPlugin.props" Pack="true" PackagePath="build"></None>
这一步是将MyPlugin.props打包到nupkg文件的build文件夹中。 Please see this document,
Build\MyPlugin.props 表示您的 MyPlugin 项目中 MyPlugin.props 的文件物理路径,以便 nuget 找到该文件。
The build folder of nupkg (3.x+) MSBuild .targets and .props files Automatically inserted into the project.
原来是nupkg的功能。
无论如何,这一步可以自己检查,请检查文件路径是否正确,然后确保文件文件夹中存在目标文件nupkg。
这是我的 nupkg 结构:
================================================ =========================
另外,在安装这个新版本的 nuget 包之前,您应该先清理 nuget 缓存以删除旧缓存,以防您仍然安装旧缓存。
之后,首先构建你的主项目执行目标,然后你会看到我在这里展示的效果。