简体   繁体   English

如何强制 msbuild 和 nuget 将引用的 Lib 打包为 dll?

[英]How to force msbuild and nuget to pack the referenced Lib as dll?

I have 2 Projects:我有2个项目:
Project A is .Net Standard 2.0项目 A 是 .Net Standard 2.0
Project B is .Net Framework 4.6.1项目 B 是 .Net Framework 4.6.1

In BI reference to A like this (csproj):在 BI 中这样引用 A (csproj):

 <ItemGroup>
<ProjectReference Include="A.csproj">
  <Project>{60DEB41B-8670-4199-95C2-FE68EB06B099}</Project>
  <Name>A</Name>
</ProjectReference>

Now when I pack a nuget of B, I can't access A because it doesnt resolve the dependency.现在,当我打包 B 的 nuget 时,我无法访问 A,因为它无法解决依赖关系。

here are the commands, run by gitlab ci, to create the project B:这是由 gitlab ci 运行的用于创建项目 B 的命令:

nuget restore nuget 还原
msbuild B.csproj msbuild B.csproj
nuget pack -version $VERSION nuget 包 -version $VERSION
dotnet nuget push **/*.nupkg ... dotnet nuget push **/*.nupkg ...

How to include the lib of A as DLL in B?如何将A的lib作为DLL包含在B中?

Actually , adding a reference at the project level does not automatically add the corresponding reference dll during the packaging process.实际上,在项目级别添加引用并不会在打包过程中自动添加相应的引用dll。 You need to add an additional dll to the nuget package manually.您需要手动将额外的dll添加到 nuget 包中。

I have two solutions:我有两个解决方案:

Solution One解决方案一

Just as Cem.S said, use -IncludeReferencedProjects to pack your project.正如Cem.S所说,使用-IncludeReferencedProjects来打包你的项目。

Also, since you pack a net framework nuget project, you only have to use nuget.exe cli to pack the project with the created nuspec file :此外,由于您打包了一个网络框架 nuget 项目,因此您只需使用 nuget.exe cli 将项目与创建的 nuspec 文件打包

Use this command to pack your project B:使用此命令打包您的项目 B:

nuget pack xxx\B.csproj -IncludeReferencedProjects

Solution two解决方案二

Or just add such node in B.nuspec file:或者只是在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>

Then , run nuget pack xxx\\B.csproj to generate the new version.然后,运行nuget pack xxx\\B.csproj以生成新版本。

Before you install the new version, you should first clean nuget caches first .安装新版本之前,您应该先清理 nuget 缓存

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM