You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2022无法创建NuGet包求助:点击Pack及dotnet pack均失效

解决Visual Studio 2022中NuGet打包失效问题

问题概述

原本通过Visual Studio 2022的「Build」→「Pack projectName」创建或更新NuGet包,该功能突然失效。已尝试StackOverflow多种解决方案无效,且已移除解决方案中的其他项目。执行dotnet pack命令后仅生成DLL文件,未生成NuGet包。

项目配置文件

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <AssemblyVersion>1.0.5.0</AssemblyVersion>
    <Copyright>Copyright 2023</Copyright>
    <Description>A internal utilities</Description>
    <FileVersion>2023.10.4.1</FileVersion>
    <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
    <ImplicitUsings>enable</ImplicitUsings>
    <IsPackable>true</IsPackable>
    <LangVersion>10.0</LangVersion>
    <Nullable>enable</Nullable>
    <PackageVersion>2.0.5</PackageVersion>
    <PackageOutputPath>\bin\Packages</PackageOutputPath>
    <RootNamespace>AC</RootNamespace>
    <TargetFrameworks>net6.0;net48</TargetFrameworks>
    <Title>AC utilities</Title>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" />
    <PackageReference Include="System.Text.Json" Version="7.0.3" />
  </ItemGroup>
</Project>

dotnet pack执行结果

**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.7.3
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************

T:\MyProjects\AC>dotnet pack
MSBuild version 17.7.1+971bf70db for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  AC -> T:\MyProjects\AC\AC\bin\Debug\net6.0\AC.dll
  AC -> T:\MyProjects\AC\AC\bin\Debug\net48\AC.dll

解决方法

  • 指定Release版本打包:默认dotnet pack会处理Debug版本,尝试明确指定Release配置并强制生成包:

    dotnet pack --configuration Release
    

    若无需重新构建,可添加--no-build参数跳过构建步骤。

  • 修正输出路径:当前<PackageOutputPath>\bin\Packages是根目录绝对路径,改为项目相对路径避免权限或路径解析问题:

    <PackageOutputPath>bin\Packages</PackageOutputPath>
    
  • 清理后重新打包:先清理项目残留文件,再执行恢复和打包流程:

    dotnet clean
    dotnet restore
    dotnet pack --configuration Release
    
  • 检查SDK兼容性:确保本地安装的.NET SDK版本支持net6.0和net48目标框架,执行dotnet --version查看当前SDK版本,必要时更新至兼容版本。

  • 临时启用自动打包测试:将<GeneratePackageOnBuild>false</GeneratePackageOnBuild>改为true,执行构建操作,验证打包流程是否正常生成NuGet包。

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 11:02:34