247 字
1 分鐘
瀏覽次數
NuGet Package Publishing and Local Testing Hands-on: From Push to Verification, A Complete Guide
2025-07-25
2026-04-10

Conclusion#

  • Testing directly with “project reference” after publishing is faster and more controllable than re-downloading the package.

Where It’s Suitable#

  • Self-hosted NuGet private server / Company internal packages
  • Developing shared tools (Logging / Utils / SDK)
  • Wanting to quickly verify functionality after publishing
  • Avoiding wasted time from repeated push / install cycles

Process Steps#

1. Push NuGet Package#

  • Upload the packaged .nupkg to the NuGet Server
  • Ensure the API Key and Server URL are correct
Terminal window
# 推送套件
dotnet nuget push -s <https://xxx.yyy.zzz/v3/index.json> -k KEYXXX1234 AppLogger.1.0.0.nupkg
  • Why:
    • Allows other projects to install via NuGet
    • Serves as the official release source

2. Test Using “Project Reference”#

  • Do not install the NuGet package directly

  • Instead, use a local project for testing Steps:

  • Right-click on the solution → Add Existing Project (package project)

  • Project → Dependencies → Add Project Reference

  • Select your package project

  • Why:

    • Changes take effect immediately (no need to repack)
    • Easier to debug (can directly step into the package code)

3. Verify Functionality#

  • Run the main project
  • Confirm:
    • Whether API / Method works correctly
    • Whether DI / configuration is correct
    • Whether dependent packages are missing
// 範例:測試 Logger 套件
var logger = new AppLogger();
logger.Log("測試訊息");

Additional Notes#

  • Don’t push the package for every test → this will slow down the development pace
  • Repackage and publish only after project reference testing is OK
  • Pay attention to the version number, otherwise NuGet might fetch an older version

Commands / Examples Summary#

Click to expend
Terminal window
# 推送 NuGet 套件
dotnet nuget push -s <https://xxx.yyy.zzz/v3/index.json> -k KEYXXX1234 AppLogger.1.0.0.nupkg

Conclusion#

  • Use project references during the testing phase, and NuGet for publishing; this keeps the workflow much cleaner.
NuGet Package Publishing and Local Testing Hands-on: From Push to Verification, A Complete Guide
https://joyceowo.github.io/posts/en/23ba78ea09fa815bab31cd64e4ab15c2/
作者
JoyceOwO
發佈於
2025-07-25
許可協議
CC BY-NC-SA 4.0