How to package .NET assemblies

How to package .NET assemblies

  • Comments 7

If we want to package and deploy .NET assemblies for a web application only, we can simply reference them and change their “Copy Local” property to “True”. 

For example, we can do the following to package a MVC project from VS2010.

  1. Create a MVC project
  2. In its references, change the following three assemblies “Copy Local” property value to True.
    • System.Web.Mvc
    • System.Web.Routing
    • System.Web.Abstractions

    You can multi-select them and set the value together.

  3. Right click the project node and select “Build Deployment Package”
  4. Examine the package, you will see the above assemblies' corresponding dll files are included in the package’s bin directory.


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.


If we want to package and deploy GACed dll, we need to use gacAssembly web deploy provider and extend our project similarly to the one stated in the how to package registry blog.  The extended projectName.wpp.targets file looks like following:


<!-- Task CollectGacAssemblyForPackage –>
<!-- GacAssembly reference: -->
<Project xmlns="">
    <!--Targets get execute before this Target-->
    <OnBeforeCollectGacAssemblyForPackage Condition="'$(OnBeforeCollectGacAssemblyForPackage)'==''">
    <!--Targets get execute after this Target-->
    <OnAfterCollectGacAssemblyForPackage Condition="'$(OnAfterCollectGacAssemblyForPackage)'==''">

    <CollectGacAssemblyForPackageDependsOn Condition="'$(CollectGacAssemblyForPackageDependsOn)'==''">

    <IncludeGacAssemblyForMyProject Condition="'$(IncludeGacAssemblyForMyProject)'==''">False</IncludeGacAssemblyForMyProject>
    <MyGacAssemblies Condition="'$(MyGacAssemblies)'==''"></MyGacAssemblies>
    <AfterAddContentPathToSourceManifest Condition="'$(AfterAddContentPathToSourceManifest)'==''">

    <MyGacAssembly Include = "$(MyGacAssemblies)"/>

  <Target Name="CollectGacAssemblyForPackage"
          Condition="$(IncludeGacAssemblyForMyProject) AND '$(MyGacAssemblies)'!=''">

    <Message Text="Adding %(MyGacAssembly.Identity)" />
      <MsDeploySourceManifest Include="gacAssembly"
    <CallTarget Targets="$(OnAfterCollectGacAssemblyForPackage)" RunEachTargetSeparately="false" />

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.

msbuild WebApplication2.csproj /target:package /p:IncludeGacAssemblyForMyProject=True;MyGacAssemblies="System.Web.Mvc;System.Web.Routing,Version=;System.Web.Abstractions,Version="

Note, gacAssembly web deploy provider has some limitation as described in the link.


Xinyang Qiu | Visual Web Developer

  • This is very useful information and i salute you. youre expert.

  • Hi its very nice article. But will that be problematic with GAC dll's ?



  • GAC dlls affects system wide, and I would avoid it if possible.  But in some automated test lab, using this way to GAC dlls for your web application might be a userful option.

  • The title of this post is misleading. None of the assemblies you're deploying are COM components; they're .NET assemblies.

  • Thanks, Richard, I just realized the error.  Title is changed to reflect the fact.  Thanks again.

  • There is another minor mistake in the post, look at the picture, it selected these following dlls




    In fact in the post's writing it asks for these dlls




  • Ray, Thanks, I've corrected the picture

Page 1 of 1 (7 items)