As people are using Visual Studio Online in combination with MyGet, we often get the request to help them set things up. We do have documentation VSO integration, but the new VSO Build Preview deserves a dedicated blog post. This blog post should guide you through the setup experience and get you going in no time!<div>
</div><h1>Configuring Package Restore</h1><div>One of the first and most easy things to do is to configure NuGet package restore in your solution.</div><div>
</div><div>When creating a MyGet feed, by default, we will configure nuget.org as an upstream package source. What is very convenient is that you can tweak it further so that:</div><div><ul><li>clients querying your MyGet feed also query the upstream nuget.org package source to resolve packages</li><li>the downstream MyGet feed automatically mirrors the packages queried upstream (thus creating a copy of the package on your MyGet feed)</li><li>you don’t see the mirrored packages in your MyGet feed, even though they’re there and can be restored (the concept of ‘unlisting’ a package)</li></ul><div>Three simple checkboxes in the package source configuration make the above possible, as shown below:</div></div><div>
</div><div>
</div><div>Once enabled, you should see the below package source configuration updated to reflect those changes.</div><div>
</div><div>
</div><div>In the code base, you should ensure you have a nuget.config file in the solution root directory. This is where you can configure NuGet package restore configuration options, including credentials for your private feed. The below snippet is a good sample of what you need there.</div><div></div><div>
</div><div>
</div><div>Be sure to add the nuget.config file to your version control system to ensure the build server also has it available.</div><div>Also, be sure to check this NuGet docs article on how to ommit packages from source control. Git users can simply ignore the packages folder in the .gitignore file, TFVC users need to create an additional nuget.config file in a directory called .nuget (created in the solution root directory). This may change in the future, so be sure to check the docs!</div><div>
</div><div>That’s it! You can now locally restore packages in your solution from both MyGet and nuget.org.</div><div>All you need to do in VSO Build Preview is to create a new Build Definition using the default Visual Studio build template and queue a build. </div><div>
</div><div>
</div><div>If you consume NuGet packages, you should now already see package restore actions in the build log.</div><div>
</div><div>
</div><div>
</div><h1>Creating NuGet packages</h1><div>For demo purposes, I’m building a simple class library and want to package-n-publish it to MyGet. We highly recommend you first create a .nuspec file for the project you want to package. You can construct this NuGet package manifest yourself, use NuGet Package Explorer, or if you have nuget.exe at your disposal, simply run nuget spec in the folder where your target project is located. </div><div>
</div><div>Note: if you run nuget spec, please ensure you have all required metadata in your AssemblyInfo file to provided the tokenized nuspec file with actual values during packaging.</div><div>
</div><div>To create the NuGet packages, you’ll need to add a PowerShell script build task to the build definition and call into nuget pack.</div><div>
</div><div>// todo: sample</div><div>// add NuGet packaging logic to the custom build task?</div><div>
</div><h1>Publish NuGet packages to MyGet</h1><div>// todo: preferably based on the custom build task</div><div>// otherwise: PoSh it..</div><div>
</div>