.NUSPEC不适用于.NET 6项目

发布于 2025-01-22 14:40:57 字数 981 浏览 1 评论 0原文

我有以下三个项目,所有项目都是使用VS2022和Targinaling .NET 6。

  1. 外部Project(.dll)
  2. InternalProject(.dll)
  3. testProject(.exe)

ExternalProject包含对InternalSproject的引用,我也正在使用Nuget Offection Proke of ExternalProject使用The ExternalProject的参考。下面命令

dotnet pack externalProject.csproj /p:nuspecfile=

externalClass.nuspec externalClass.nuspec文件的内容低于

<?xml version="1.0"?>
<package >
  <metadata>
    <id>ExternalProject</id>
    <version>1.0.10</version>
    <title>ExternalProject</title>
    <authors>Ustad</authors>
    <owners>Ustad</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
  </metadata>
  <files>
    <file src="..\InternalProject\bin\Debug\net6.0\*.*" target="lib\net6.0" />
  </files>
</package>

问题,是,InternalProject DLL未添加到外部Prothignt Nuget软件包中。不知道我在这里缺少什么。

I have below three projects, all are created using VS2022 and targeting .net 6.

  1. ExternalProject (.dll)
  2. InternalProject (.dll)
  3. TestProject (.exe)

ExternalProject contains a reference to the InternalProject, also I am creating NuGet package of ExternalProject using the below command

dotnet pack ExternalProject.csproj /p:NuspecFile=ExternalClass.nuspec

The content of ExternalClass.nuspec file is below

<?xml version="1.0"?>
<package >
  <metadata>
    <id>ExternalProject</id>
    <version>1.0.10</version>
    <title>ExternalProject</title>
    <authors>Ustad</authors>
    <owners>Ustad</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
  </metadata>
  <files>
    <file src="..\InternalProject\bin\Debug\net6.0\*.*" target="lib\net6.0" />
  </files>
</package>

The problem is, that InternalProject dll is not being added to the ExternalProject NuGet package. Not sure what I am missing here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

肤浅与狂妄 2025-01-29 14:40:57

我得到了解决方案,应该编辑externalProject.csproj文件,然后在XML下添加。还将在ProjectReference元素中添加privateasetss =“ all”。

<PropertyGroup>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetMyPackageFiles</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>

<Target Name="GetMyPackageFiles">
    <ItemGroup>
        <BuildOutputInPackage Include="$(OutputPath)InternalProject.dll">
        </BuildOutputInPackage>
    </ItemGroup>
</Target>

I got the solution, one should edit ExternalProject.csproj file and add below xml. Also add PrivateAssets="all" in the ProjectReference element.

<PropertyGroup>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetMyPackageFiles</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>

<Target Name="GetMyPackageFiles">
    <ItemGroup>
        <BuildOutputInPackage Include="$(OutputPath)InternalProject.dll">
        </BuildOutputInPackage>
    </ItemGroup>
</Target>
刘备忘录 2025-01-29 14:40:57

由于我的评论中的答案比当前 Documentation 我在这里包括。

根据文档:

nuget依赖项被添加到.nuspec文件中,因此安装软件包时它们可以正确解决。如果包装的项目提到了其他项目,则包装中未包含其他项目。目前,如果您有项目对项目依赖项,则必须有一个计划。

即,就像链接的答案所说的那样,除了发布每个项目的包裹外,别无其他方法。如果不是一个选择,则可以使用其中描述的工作。

Since the answer in my comment is one year older than the current documentation I'll include here.

According to the docs:

NuGet dependencies of the packed project are added to the .nuspec file, so they're properly resolved when the package is installed. If the packed project has references to other projects, the other projects are not included in the package. Currently, you must have a package per project if you have project-to-project dependencies.

I.e. just like the linked answer says, there's no official way to do it other than publishing a package per project. If that's not an option, you can use the work arounds described there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文