Nuget的项目参考

发布于 2025-01-30 06:27:37 字数 2370 浏览 3 评论 0原文

我需要创建一个依赖于项目B的项目A的nuget(不是Nuget项目,本地项目)。

我将项目B作为项目依赖项添加到项目A和启用属性以在构建上生成软件包。它正在创建Nuget软件包文件,但不包括Project A中的所有文件。 我也尝试过几件事,也没有找到太多帮助。

我发现了一个类似的问题 但不起作用。我可以创建pkg,但是很少复制文件。虽然我可以在调试文件夹中看到所有文件。不知道Nuget从Project A中挑选几个文件。

任何人都可以告诉我这里有什么问题。

<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <PackageVersion>1.0.0.0-alpha</PackageVersion>
    <Platforms>x64</Platforms>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <PlatformTarget>x64</PlatformTarget>
    <NoWarn></NoWarn>
    <WarningsAsErrors />
    <OutputPath>bin\Debug</OutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <PlatformTarget>x64</PlatformTarget>
    <NoWarn></NoWarn>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <WarningsAsErrors />
    <OutputPath>bin\Release</OutputPath>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="System.Configuration" />
  </ItemGroup>

  <ItemGroup>

    <ProjectReference Include="someProject.csproj">
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
     <IncludeAssets>all</IncludeAssets>
    </ProjectReference>
  </ItemGroup>

  <Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
    <ItemGroup>
      <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))"/>
    </ItemGroup>
  </Target>

</Project>

I need to create a Nuget of project A which is dependent on project B (not a nuget project, local one).

I have added Project B as project dependency to project A and enabled property to generate package on build. It is creating nuget package file but not including all the files from project A.
I tried few things and google also but not finding much help.

I found one similar question Build NuGet Package automatically including referenced dependencies
but not working. I am able to create pkg but with few files copied over. while I can see all the files in debug folder. No idea on what basis Nuget is picking few files from project A.

Can anyone tell me what's wrong here.

<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <PackageVersion>1.0.0.0-alpha</PackageVersion>
    <Platforms>x64</Platforms>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <PlatformTarget>x64</PlatformTarget>
    <NoWarn></NoWarn>
    <WarningsAsErrors />
    <OutputPath>bin\Debug</OutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <PlatformTarget>x64</PlatformTarget>
    <NoWarn></NoWarn>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <WarningsAsErrors />
    <OutputPath>bin\Release</OutputPath>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="System.Configuration" />
  </ItemGroup>

  <ItemGroup>

    <ProjectReference Include="someProject.csproj">
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
     <IncludeAssets>all</IncludeAssets>
    </ProjectReference>
  </ItemGroup>

  <Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
    <ItemGroup>
      <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))"/>
    </ItemGroup>
  </Target>

</Project>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文