{"id":3264,"date":"2010-02-19T18:53:01","date_gmt":"2010-02-19T18:53:01","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2010\/02\/19\/how-to-package-net-assemblies\/"},"modified":"2010-02-19T18:53:01","modified_gmt":"2010-02-19T18:53:01","slug":"how-to-package-net-assemblies","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/how-to-package-net-assemblies\/","title":{"rendered":"How to package .NET assemblies"},"content":{"rendered":"<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"774\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"532\">\n<p>If we want to package and deploy .NET assemblies for a web application only, we can simply reference them and change their \u201cCopy Local\u201d property to \u201cTrue\u201d.&#160; <\/p>\n<p>For example, we can do the following to package a MVC project from VS2010.<\/p>\n<\/p>\n<ol>\n<li>Create a MVC project <\/li>\n<li>In its references, change the following three assemblies \u201cCopy Local\u201d property value to True.              \n<ul>\n<li>System.Web.Mvc <\/li>\n<li>System.Web.Routing <\/li>\n<li>System.Web.Abstractions <\/li>\n<\/ul>\n<p>You can multi-select them and set the value together. <\/p>\n<\/li>\n<li>Right click the project node and select \u201cBuild Deployment Package\u201d <\/li>\n<li>Examine the package, you will see the above assemblies&#8217; corresponding dll files are included in the package\u2019s bin directory. <\/li>\n<\/ol>\n<p>&#160;<\/p>\n<p>Deploy the above package to a 4.0 site, no matter if the corresponding MVC runtime is installed on the server, your application will simply work fine.<\/p>\n<\/td>\n<td valign=\"top\" width=\"240\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_5.png\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2010\/02\/image_thumb.png\" width=\"213\" height=\"544\" \/><\/a> <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If we want to package and deploy GACed dll, we need to use <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd569056(WS.10).aspx\">gacAssembly web deploy provider<\/a> and extend our project similarly to the one stated in the <a href=\"http:\/\/blogs.msdn.com\/webdevtools\/archive\/2010\/02\/09\/how-to-extend-target-file-to-include-registry-settings-for-web-project-package.aspx\">how to package registry blog<\/a>.&#160; The extended projectName.wpp.targets file looks like following:<\/p>\n<p>&#160;<\/p>\n<pre class=\"code\"><span style=\"color: blue\">&lt;!--<\/span><span style=\"color: green\">********************************************************************<\/span><span style=\"color: blue\">--&gt;\n&lt;!-- <\/span><span style=\"color: green\">Task CollectGacAssemblyForPackage \u2013<\/span><span style=\"color: blue\">&gt;\n<\/span><span style=\"color: blue\">&lt;!-- <\/span><span style=\"color: green\">GacAssembly reference: http:\/\/technet.microsoft.com\/en-us\/library\/dd569056(WS.10).aspx <\/span><span style=\"color: blue\">--&gt;\n<\/span><span style=\"color: blue\">&lt;!--<\/span><span style=\"color: green\">********************************************************************<\/span><span style=\"color: blue\">--&gt;\n&lt;<\/span><span style=\"color: #a31515\">Project <\/span><span style=\"color: red\">xmlns<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">http:\/\/schemas.microsoft.com\/developer\/msbuild\/2003<\/span>&quot;<span style=\"color: blue\">&gt;\n  &lt;<\/span><span style=\"color: #a31515\">PropertyGroup<\/span><span style=\"color: blue\">&gt;\n    &lt;!--<\/span><span style=\"color: green\">Targets get execute before this Target<\/span><span style=\"color: blue\">--&gt;\n    &lt;<\/span><span style=\"color: #a31515\">OnBeforeCollectGacAssemblyForPackage <\/span><span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">'$(OnBeforeCollectGacAssemblyForPackage)'==''<\/span>&quot;<span style=\"color: blue\">&gt;\n    &lt;\/<\/span><span style=\"color: #a31515\">OnBeforeCollectGacAssemblyForPackage<\/span><span style=\"color: blue\">&gt;\n    &lt;!--<\/span><span style=\"color: green\">Targets get execute after this Target<\/span><span style=\"color: blue\">--&gt;\n    &lt;<\/span><span style=\"color: #a31515\">OnAfterCollectGacAssemblyForPackage <\/span><span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">'$(OnAfterCollectGacAssemblyForPackage)'==''<\/span>&quot;<span style=\"color: blue\">&gt;\n    &lt;\/<\/span><span style=\"color: #a31515\">OnAfterCollectGacAssemblyForPackage<\/span><span style=\"color: blue\">&gt;\n\n    &lt;<\/span><span style=\"color: #a31515\">CollectGacAssemblyForPackageDependsOn <\/span><span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">'$(CollectGacAssemblyForPackageDependsOn)'==''<\/span>&quot;<span style=\"color: blue\">&gt;\n      <\/span>$(OnBeforeCollectGacAssemblyForPackage);\n      Build;\n    <span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">CollectGacAssemblyForPackageDependsOn<\/span><span style=\"color: blue\">&gt;\n  &lt;\/<\/span><span style=\"color: #a31515\">PropertyGroup<\/span><span style=\"color: blue\">&gt;\n\n  &lt;<\/span><span style=\"color: #a31515\">PropertyGroup<\/span><span style=\"color: blue\">&gt;\n    &lt;<\/span><span style=\"color: #a31515\">IncludeGacAssemblyForMyProject <\/span><span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">'$(IncludeGacAssemblyForMyProject)'==''<\/span>&quot;<span style=\"color: blue\">&gt;<\/span>False<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">IncludeGacAssemblyForMyProject<\/span><span style=\"color: blue\">&gt;\n    &lt;<\/span><span style=\"color: #a31515\">MyGacAssemblies <\/span><span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">'$(MyGacAssemblies)'==''<\/span>&quot;<span style=\"color: blue\">&gt;&lt;\/<\/span><span style=\"color: #a31515\">MyGacAssemblies<\/span><span style=\"color: blue\">&gt;\n    &lt;<\/span><span style=\"color: #a31515\">AfterAddContentPathToSourceManifest <\/span><span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">'$(AfterAddContentPathToSourceManifest)'==''<\/span>&quot;<span style=\"color: blue\">&gt;\n      <\/span>$(AfterAddContentPathToSourceManifest);\n      CollectGacAssemblyForPackage;\n    <span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">AfterAddContentPathToSourceManifest<\/span><span style=\"color: blue\">&gt;\n  &lt;\/<\/span><span style=\"color: #a31515\">PropertyGroup<\/span><span style=\"color: blue\">&gt;\n\n  &lt;<\/span><span style=\"color: #a31515\">ItemGroup<\/span><span style=\"color: blue\">&gt;\n    &lt;<\/span><span style=\"color: #a31515\">MyGacAssembly <\/span><span style=\"color: red\">Include <\/span><span style=\"color: blue\">= <\/span>&quot;<span style=\"color: blue\">$(MyGacAssemblies)<\/span>&quot;<span style=\"color: blue\">\/&gt;\n  &lt;\/<\/span><span style=\"color: #a31515\">ItemGroup<\/span><span style=\"color: blue\">&gt;\n\n  &lt;<\/span><span style=\"color: #a31515\">Target <\/span><span style=\"color: red\">Name<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">CollectGacAssemblyForPackage<\/span>&quot;\n          <span style=\"color: red\">DependsOnTargets<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">$(CollectGacAssemblyForPackageDependsOn)<\/span>&quot;\n          <span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">$(IncludeGacAssemblyForMyProject) AND '$(MyGacAssemblies)'!=''<\/span>&quot;<span style=\"color: blue\">&gt;\n\n    &lt;<\/span><span style=\"color: #a31515\">Message <\/span><span style=\"color: red\">Text<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">Adding %(MyGacAssembly.Identity)<\/span>&quot; <span style=\"color: blue\">\/&gt;\n    &lt;<\/span><span style=\"color: #a31515\">ItemGroup<\/span><span style=\"color: blue\">&gt;\n      &lt;<\/span><span style=\"color: #a31515\">MsDeploySourceManifest <\/span><span style=\"color: red\">Include<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">gacAssembly<\/span>&quot;\n                                 <span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">$(IncludeGacAssemblyForMyProject)<\/span>&quot;<span style=\"color: blue\">&gt;\n        &lt;<\/span><span style=\"color: #a31515\">Path<\/span><span style=\"color: blue\">&gt;<\/span>%(MyGacAssembly.Identity)<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">Path<\/span><span style=\"color: blue\">&gt;\n      &lt;\/<\/span><span style=\"color: #a31515\">MsDeploySourceManifest<\/span><span style=\"color: blue\">&gt;\n    &lt;\/<\/span><span style=\"color: #a31515\">ItemGroup<\/span><span style=\"color: blue\">&gt;\n    &lt;<\/span><span style=\"color: #a31515\">CallTarget <\/span><span style=\"color: red\">Targets<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">$(OnAfterCollectGacAssemblyForPackage)<\/span>&quot; <span style=\"color: red\">RunEachTargetSeparately<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">false<\/span>&quot; <span style=\"color: blue\">\/&gt;\n  &lt;\/<\/span><span style=\"color: #a31515\">Target<\/span><span style=\"color: blue\">&gt;\n&lt;\/<\/span><span style=\"color: #a31515\">Project<\/span><span style=\"color: blue\">&gt;\n\n<\/span><\/pre>\n<p>Then you can use the following command line to package the project with corresponding Mvc GACs and 4.0 version of System.Web.Routing and System.Web.Abstractions.<\/p>\n<p><em>msbuild WebApplication2.csproj \/target:package \/p:IncludeGacAssemblyForMyProject=True;MyGacAssemblies=&quot;System.Web.Mvc;System.Web.Routing,Version=4.0.0.0;System.Web.Abstractions,Version=4.0.0.0&quot;<\/em><\/p>\n<p>Note, <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd569056(WS.10).aspx\">gacAssembly web deploy provider<\/a> has some limitation as described in the link. <\/p>\n<p>&#160;<\/p>\n<p>Xinyang Qiu | Visual Web Developer<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If we want to package and deploy .NET assemblies for a web application only, we can simply reference them and change their \u201cCopy Local\u201d property to \u201cTrue\u201d.&#160; For example, we can do the following to package a MVC project from VS2010. Create a MVC project In its references, change the following three assemblies \u201cCopy Local\u201d [&hellip;]<\/p>\n","protected":false},"author":404,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[7351,7286,7352,7353,7354,7323,7329],"class_list":["post-3264","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-gac","tag-mvc","tag-package","tag-target-extension","tag-target-file","tag-visual-studio-2010","tag-web-deployment"],"acf":[],"blog_post_summary":"<p>If we want to package and deploy .NET assemblies for a web application only, we can simply reference them and change their \u201cCopy Local\u201d property to \u201cTrue\u201d.&#160; For example, we can do the following to package a MVC project from VS2010. Create a MVC project In its references, change the following three assemblies \u201cCopy Local\u201d [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/3264","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\/404"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=3264"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/3264\/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=3264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=3264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=3264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}