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

如何修改已推送至源的NuGet包名称(Sample→SamplePackageForTesting)

解决方案:修改NuGet包显示名称或迁移至新包

首先明确NuGet的核心规则:

  • <id>是包的唯一标识符,源中通过id+version区分不同包,修改<id>推送必然生成新包,这是NuGet的设计逻辑。
  • <title>是包的显示名称,仅用于客户端展示,但已推送的包版本默认无法直接更新元数据,需开启源的覆盖权限。

方案1:更新现有包的显示名称(保留原id)

仅适用于支持覆盖已发布版本的私有源(如Azure Artifacts):

  1. 编辑nuspec文件,将<title>字段改为SamplePackageForTesting,保持<id>为Sample不变:
    <?xml version="1.0" encoding="utf-8"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
      <metadata>
           <id>Sample</id>
          <version>1.0.0.0</version>
            <title>SamplePackageForTesting</title>
        <authors>Name</authors>
        <copyright>Copyright © 2009-2019. All rights reserved.</copyright>   
        <tags>Sample</tags>  
        <description>This package is for testing. Updated display name to SamplePackageForTesting</description>
        <owners>Name</owners>  
      </metadata>
      <files>   
        <file src="./Sample.dll" target="lib\net46\Sample.dll"/>
      </files>
    </package>
    
  2. 重新生成nupkg文件:
    nuget pack Sample.nuspec
    
  3. 在Azure DevOps的NuGet Push任务中:
    • 勾选允许重复推送(对应命令行参数nuget push -SkipDuplicate false)
    • 确保你的Azure Artifacts源已开启允许更新包的设置(在源的"Feed settings"中找到"Allow packages to be updated"选项并启用)
  4. 推送修改后的nupkg至源,覆盖原版本。
  5. 清理本地NuGet缓存以查看更新:
    nuget locals all -clear
    

方案2:迁移至新id的包(彻底改名)

如果需要将包的唯一标识改为SamplePackageForTesting,只能发布新包,同时平滑过渡:

  1. 编辑nuspec文件,将<id>和<title>都改为SamplePackageForTesting,版本可延续或升级:
    <?xml version="1.0" encoding="utf-8"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
      <metadata>
           <id>SamplePackageForTesting</id>
          <version>1.0.0.0</version>
            <title>SamplePackageForTesting</title>
        <authors>Name</authors>
        <copyright>Copyright © 2009-2019. All rights reserved.</copyright>   
        <tags>Sample Testing</tags>  
        <description>This package is the renamed version of the original Sample package.</description>
        <owners>Name</owners>  
      </metadata>
      <files>   
        <file src="./Sample.dll" target="lib\net46\Sample.dll"/>
      </files>
    </package>
    
  2. 生成新的nupkg并推送至源。
  3. 对原Sample包进行维护:
    • 在其描述中添加迁移说明,引导用户切换到SamplePackageForTesting
    • 在Azure Artifacts中将原包标记为已弃用(在包详情页的"Status"中设置)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 07:10:12