每个构建后,如何自动将.targets文件自动添加到Nuget软件包中?
我对MSBuild,Nuget软件包和.Targets文件等概念非常陌生,所以请忍受我:)
我有一个C#项目,该项目应该生成一个包含本机DLL的Nuget软件包。我可以使此工作工作,但是当我将Nuget软件包安装在另一个C#项目中时,本机DLL不会复制。对于此问题,这个问题似乎很有帮助:
但是,那里的所有解决方案都提到在Nuget软件包内的构建文件夹中添加.targets文件。 但是我该怎么做???换句话说,我在何处将此.targets文件放在我的源代码中,以便在构建项目并生成Nuget软件包时,将.targets文件添加到Nuget软件包(在“构建”文件夹下)?
这是在每个构建上生成的Nuget软件包的当前内容(请注意,没有.targets文件):
root
| Com.CompanyName.Sdk.nuspec
| [Content_Types].xml
|
+---lib
| +---native
| | Com.CompanyName.Hashing.dll
| |
| \---netcoreapp3.1
| Com.CompanyName.Sdk.dll
| Com.CompanyName.Core.dll
|
+---package
| \---services
| \---metadata
| \---core-properties
| b2b8c6e91425459ba050043277f18f48.psmdcp
|
\---_rels
.rels
我以为我可能必须将.targets文件放在与CSPROJ文件同一位置的位置,因此它位于CSPROJ所在的项目的根目录。
这是我的NUSPEC文件的内容,它也位于项目的根目录中:
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
.....some metadata here.....
<dependencies>
<group targetFramework="netcoreapp3.1"></group>
<group targetFramework="native"></group>
</dependencies>
</metadata>
<files>
<file src="Com.CompanyName.Sdk.dll" target="lib\netcoreapp3.1" />
<file src="Com.CompanyName.Core.dll" target="lib\netcoreapp3.1" />
<file src="Com.CompanyName.Hashing.dll" target="lib\native" />
</files>
</package>
另外,如果在底部的NUSPEC中添加以下导入,则使用其他导入...
<file src="Com.CompanyName.Sdk.targets" target="build\Com.CompanyName.Sdk.targets.targets" />
...我遇到了一个MSBUILD错误,找不到.targets文件:
C:\Program Files\dotnet\sdk\5.0.408\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5019: File not found: 'Microso
ft.Com.CompanyName.Sdk.targets'. [C:\git\sdk\sources\dev\Sdk\Com.CompanyName.Sdk.csproj]
那么如何修复此问题?
I'm extremely new to concepts like msbuild, nuget packages and .targets files, so please bear with me :)
I have a C# project which is supposed to generate a Nuget package which contains a native DLL. I'm able to get this working, but when I install that Nuget package in another C# project, the native DLLs are not copied over. For this issue, this question seems to be helpful:
Add native files from NuGet package to project output directory
However all the solutions there mention adding a .targets file into the build folder inside the nuget package. But how do I do this ??? In other words, where do I place this .targets file in my source code, such that when the project is built and the nuget package is generated, the .targets file is added into the nuget package (under 'build' folder) ??
This is the current contents of the nuget package that's generated on every build (notice that there's no .targets file):
root
| Com.CompanyName.Sdk.nuspec
| [Content_Types].xml
|
+---lib
| +---native
| | Com.CompanyName.Hashing.dll
| |
| \---netcoreapp3.1
| Com.CompanyName.Sdk.dll
| Com.CompanyName.Core.dll
|
+---package
| \---services
| \---metadata
| \---core-properties
| b2b8c6e91425459ba050043277f18f48.psmdcp
|
\---_rels
.rels
I assumed I might have to place the .targets file in the same location as the CSPROJ file, so currently it's located at the root directory of the project where the CSPROJ is also located.
This is the contents of my NUSPEC file, which is also in the root directory of the project:
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
.....some metadata here.....
<dependencies>
<group targetFramework="netcoreapp3.1"></group>
<group targetFramework="native"></group>
</dependencies>
</metadata>
<files>
<file src="Com.CompanyName.Sdk.dll" target="lib\netcoreapp3.1" />
<file src="Com.CompanyName.Core.dll" target="lib\netcoreapp3.1" />
<file src="Com.CompanyName.Hashing.dll" target="lib\native" />
</files>
</package>
Also, if the add the following import in the NUSPEC at the bottom with the other imports ...
<file src="Com.CompanyName.Sdk.targets" target="build\Com.CompanyName.Sdk.targets.targets" />
... I get an msbuild error that the .targets file isn't found:
C:\Program Files\dotnet\sdk\5.0.408\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5019: File not found: 'Microso
ft.Com.CompanyName.Sdk.targets'. [C:\git\sdk\sources\dev\Sdk\Com.CompanyName.Sdk.csproj]
So how do I fix this ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论