我有 2 个项目:
项目A是.Net Standard 2.0
项目B是.Net Framework 4.6.1
在 B 中,我像这样引用 A (csproj):
<ItemGroup>
<ProjectReference Include="A.csproj">
<Project>{60DEB41B-8670-4199-95C2-FE68EB06B099}</Project>
<Name>A</Name>
</ProjectReference>
现在,当我打包 B 的 nuget 时,我无法访问 A,因为它无法解决依赖关系。
以下是由 gitlab ci 运行的命令,用于创建项目 B:
nuget 恢复
msbuild B.csproj
nuget pack -版本 $VERSION
dotnet nuget 推送 **/*.nupkg ...
如何将A的lib作为DLL包含在B中?
最佳答案
实际上,在项目级别添加引用并不会在打包过程中自动添加对应的引用dll。您需要手动向 nuget 包中添加一个额外的 dll
。
我有两个解决方案:
解决方案一
正如如Cem.S
所说,使用-IncludeReferencedProjects
来打包您的项目。
此外,由于您打包了一个 net Framework nuget 项目,因此您只需 use nuget.exe cli to pack the project with the created nuspec file :
使用此命令打包您的项目B:
nuget pack xxx\B.csproj -IncludeReferencedProjects
解决方案二
或者只需在B.nuspec
文件中添加这样的节点:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>xxx</id>
<version>1.0.0</version>
<title>xxx</title>
<authors>xxx</authors>
.....
</metadata>
<files>
<file src="xxx\xxx\A.dll" target="lib\net461" />
<files>
</package>
然后,运行nuget pack xxx\B.csproj
生成新版本。
在安装新版本之前,您应该first clean nuget caches first .
关于c# - 如何强制msbuild和nuget将引用的Lib打包为dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64500666/