{"id":147,"date":"2012-12-31T00:00:00","date_gmt":"2012-12-31T08:00:00","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/nuget\/a-quick-tutorial-on-update-package-command"},"modified":"2012-12-31T00:00:00","modified_gmt":"2012-12-31T08:00:00","slug":"a-quick-tutorial-on-update-package-command","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/a-quick-tutorial-on-update-package-command\/","title":{"rendered":"A quick tutorial on the Update-Package command"},"content":{"rendered":"<p>Among the supported commands in NuGet&#8217;s Package Manager Console, <strong>Update-Package<\/strong> is arguably the most powerful in terms of its supported parameters and switches. The primary purpose of the command is to update package(s) in your projects to a higher (possibly latest) version. However, the provided parameters allow you to twist this behavior in many different ways. In this post, I&#8217;m going to give a quick tutorial on what possible ways you can invoke the command.<\/p>\n<p>In total, the <strong>Update-Package<\/strong> command offers eight parameters (in addition to the built-in PowerShell parameters):<\/p>\n<table cellspacing=\"0\" cellpadding=\"6\" border=\"1\">\n<tr>\n<th>Parameter<\/th>\n<th>Type<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td>-Id<\/td>\n<td>string<\/td>\n<td>Specifies the Id of the package to be updated.<\/td>\n<\/tr>\n<tr>\n<td>-ProjectName<\/td>\n<td>string<\/td>\n<td>Specifies the name of the project in which packages should be updated.<\/td>\n<\/tr>\n<tr>\n<td>-Version<\/td>\n<td>SemanticVersion*<\/td>\n<td>Specifies the new target version of the package as a result of the update.<\/td>\n<\/tr>\n<tr>\n<td>-Source<\/td>\n<td>string<\/td>\n<td>Specifies where to look for package updates, overriding the package sources that are specified in the Options dialog. This value can be either a url to a remote repository or a path to a local repository or the name of a package source specified in the Options dialog.<\/td>\n<\/tr>\n<tr>\n<td>-IgnoreDependencies<\/td>\n<td>Switch parameter<\/td>\n<td>If set, NuGet will ignore dependency packages and only update the main package.<\/td>\n<\/tr>\n<tr>\n<td>-Safe<\/td>\n<td>Switch parameter<\/td>\n<td>If set, NuGet will only update to a new version that has the same major and minor versions as the previous package. For example, if the old version is 1.2.0, NuGet will accept the update package with version of 1.2.1 or 1.2.9999 but it will <em>not<\/em> accept 1.3.0.<\/td>\n<\/tr>\n<tr>\n<td>-IncludePrerelease<\/td>\n<td>Switch parameter<\/td>\n<td>If set, NuGet will consider prerelease packages as candidates for updates.<\/td>\n<\/tr>\n<tr>\n<td>-Reinstall<\/td>\n<td>Switch parameter<\/td>\n<td>If set, instead of updating the package to the latest version, NuGet will uninstall the package and reinstall the same version. This is useful when, for example, you&#8217;ve updated the target framework of your project, e.g. from .NET 4.0 to .NET 4.5, and you want to reference .NET 4.5-specific assemblies in the package. You can&#8217;t set this parameter together with the -Version parameter.<\/td>\n<\/tr>\n<\/table>\n<p><code>*<\/code>Although the type of the -Version parameter is <strong>SemanticVersion<\/strong>, which is a type declared by NuGet, you can just use string when you set it. PowerShell will automatically convert it for you, as long as the value can be parsed by the <strong>SemanticVersion<\/strong> class.<\/p>\n<p>With that, here are the common use cases for the Update-Package command:<\/p>\n<ul>\n<li>\n<p>Update a particular package in a project to the latest version:<br> <code><strong>Update-Package<\/strong> jQuery <strong>-ProjectName<\/strong> MyProject<\/code><\/p>\n<\/li>\n<li>\n<p>Update a particular package in a project to the latest version, using safe update rule:<br> <code><strong>Update-Package<\/strong> jQuery <strong>-ProjectName<\/strong> MyProject <strong>-Safe<\/strong><\/code><\/p>\n<\/li>\n<li>\n<p>Update a particular package in a project to a particular version:<br> <code><strong>Update-Package<\/strong> jQuery <strong>-ProjectName<\/strong> MyProject <strong>-Version<\/strong> 1.8<\/code><\/p>\n<\/li>\n<li>\n<p>Update a particular package in <em>all<\/em> projects of the current solution to the latest version:<br> <code><strong>Update-Package<\/strong> jQuery<\/code><\/p>\n<\/li>\n<li>\n<p>Update a particular package in <em>all<\/em> projects of the current solution to a particular version:<br> <code><strong>Update-Package<\/strong> jQuery <strong>-version<\/strong> 1.8<\/code><\/p>\n<\/li>\n<li>\n<p>Reinstall a particular package in <em>all<\/em> projects of the current solution:<br> <code><strong>Update-Package<\/strong> jQuery <strong>-reinstall<\/strong><\/code><\/p>\n<\/li>\n<li>\n<p>Update <em>all<\/em> packages in a project to the latest versions:<br> <code><strong>Update-Package<\/strong> <strong>-ProjectName<\/strong> MyProject<\/code><\/p>\n<\/li>\n<li>\n<p>Reinstall <em>all<\/em> packages in a project:<br> <code><strong>Update-Package<\/strong> <strong>-ProjectName<\/strong> MyProject <strong>-reinstall<\/strong><\/code><\/p>\n<\/li>\n<li>\n<p>Update <em>all<\/em> packages in <em>all<\/em> projects of the current solution to the latest versions:<br> <code><strong>Update-Package<\/strong><\/code><\/p>\n<\/li>\n<li>\n<p>Reinstall <em>all<\/em> packages in <em>all<\/em> projects of the current solution:<br> <code><strong>Update-Package<\/strong> <strong>-Reinstall<\/strong><\/code><\/p>\n<\/li>\n<\/ul>\n<p>Phew, that&#8217;s a lot of different combinations; but they are quite intuitive and easy to remember. To keep the list small, I left out the -IgnoreDependencies and -IncludePrelease parameters but you can add either (or both) of them to any of the example above (except that you can&#8217;t use -Version and -Reinstall together, remember?) to adjust the behavior of the command.<\/p>\n<p>Hope that helps. Happy New Year.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Among the supported commands in NuGet&#8217;s Package Manager Console, Update-Package is arguably the most powerful in terms of its supported parameters and switches. The primary purpose of the command is to update package(s) in your projects to a higher (possibly latest) version. However, the provided parameters allow you to twist this behavior in many different [&hellip;]<\/p>\n","protected":false},"author":4268,"featured_media":58792,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7934,7874],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-insights","category-nuget"],"acf":[],"blog_post_summary":"<p>Among the supported commands in NuGet&#8217;s Package Manager Console, Update-Package is arguably the most powerful in terms of its supported parameters and switches. The primary purpose of the command is to update package(s) in your projects to a higher (possibly latest) version. However, the provided parameters allow you to twist this behavior in many different [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/4268"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}