如何通过Azure Artifacts结合Squirrel更新C# .Net Framework控制台应用?
Absolutely, your workaround is totally viable—and actually a common approach when combining Squirrel with Azure DevOps Artifacts! Let’s walk through how to implement this smoothly:
1. Generate Squirrel-Compatible NuGet Packages
Squirrel relies on NuGet packages under the hood, so first you’ll need to ensure your build process generates the right artifacts:
- Use the Squirrel.Windows NuGet package in your project, then run the
releasifycommand to create a release package. For example, in a command line or Azure DevOps Pipeline step:
This will output a full Squirrel release set, including theSquirrel --releasify MyConsoleApp.1.0.0.nupkg --releaseDir ./squirrel-releaseRELEASESfile, versioned.nupkgupdates, and (optionally) a setup executable. - If you’re using Azure DevOps Pipelines, you can add a script task to automate this after building your app.
2. Upload Squirrel Packages to Azure DevOps Artifacts
Once you have your Squirrel release package, push it to your Artifacts NuGet feed:
- Automated Pipeline Push: Use the NuGet Push task in your pipeline. Configure it to target your Artifacts feed, and use a service connection or PAT (Personal Access Token) with permissions to push packages.
- Manual Upload: Navigate to your Artifacts feed in Azure DevOps, click the Upload button, and select the Squirrel-generated
.nupkg(theRELEASESfile is often included inside the package, but you can upload it separately if needed). - Ensure your feed has the right permissions so your console app can access and download packages (e.g., grant "Reader" access to the service account or user running the app).
3. Download Packages in Your Console App & Trigger Squirrel Updates
Your app will need to handle fetching the latest package from Artifacts, then hand it off to Squirrel:
- First, use the
NuGet.Protocollibrary to query your Artifacts feed for the latest version of your Squirrel package. This lets you compare the remote version to your app’s current version to decide if an update is needed. - Once you confirm an update is available, download the
.nupkgto a temporary local directory (e.g.,%TEMP%\MyAppUpdates). You can extract theRELEASESfile from the package or pull it directly from the feed if you uploaded it separately. - Initialize Squirrel’s
UpdateManagerpointing to this local directory, then run the update:using (var manager = new UpdateManager(@"C:\Temp\MyAppUpdates")) { await manager.UpdateApp(); } - Note: Ensure your app has write permissions to the temporary directory and its installation path—Squirrel needs to replace files during the update process.
4. Pro Tips for a Smooth Workflow
- Automate Everything: Tie the build, Squirrel packaging, and Artifacts push into a single Azure DevOps Pipeline. Use build number variables to auto-increment versions, so every release is properly versioned and pushed to your feed.
- Handle Update Failures Gracefully: Add error handling around the download and update steps—for example, if the Artifacts feed is unavailable, fall back to skipping the update and notify the user.
- Test Locally First: Validate the flow on your machine before deploying the pipeline—download the package from Artifacts manually, point Squirrel to the local files, and confirm the update works as expected.
Your initial idea is spot-on—this approach aligns perfectly with Squirrel’s NuGet-based update model and Azure DevOps Artifacts’ hosting capabilities. If you hit snags with pipeline config, authentication, or Squirrel’s update logic, feel free to share more specifics!
内容的提问来源于stack exchange,提问作者Tomás Familia

