.netvisual-studiosharepointdllwindows-server-2012-r2

VS2015 build error: Cannot add the specified assembly to the global assembly cache


I'm trying to deploy GAC into the sharepoint. Deployment fails with this error message:

Error occured in deployment step 'Add Solution': Error: Cannot add the specified assembly to the global assembly cache: Microsoft.Practices.Sharepoint.Common.dll

The problem is that mentioned .dll inside C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Practices.SharePoint.Common\v4.0_2.0.0.0__ef4330804b3c4129\ folder is somehow locked by another .dll called Microsoft.Alm.Shared.Remoting.RemoteContainer.dll.

Only one working solution is restarting windows server, but problem will happen again once I will try to deploy a newer version.

Is there any other solution how to prevent blocking this and other similar dlls?

Thanks


Solution

  • The process named Microsoft.Alm.Shared.Remoting.RemoteContainer.dll supplies the feature "CodeLens" in the Visual Studio IDE. This feature supplies some nice functionality in VS like live display of references to functions above their declaration, source control status, test status and some others.

    The problem will go away if you disable "CodeLens" in Visual Studio at

    Visual Studio Options > Text Editor > All Languages > Code Lens

    Visual Studio Options > Text Editor > All Languages > Code Lens

    If you don't want to disable CodeLens all the time on that computer, you can just kill Microsoft.Alm.Shared.Remoting.RemoteContainer.dll before deploying. This will temporarily disable CodeLens in all running instances of Visual Studio, but CodeLens will work again after restarting Visual Studio.

    To automate killing the process before trying to register the assembly to the GAC (Global Assembly Cache), add the following command to the same place before your call to gacutil:

    taskkill /f /im Microsoft.Alm.Shared.Remoting.RemoteContainer.dll
    

    The actual trigger of the problem is that at least one of your projects in the solution loads the assembly Microsoft.Practices.Sharepoint.Common.dll from the GAC from within the Visual Studio IDE. You can prevent this by having the assembly reference point to a version of Microsoft.Practices.Sharepoint.Common.dll outside the GAC.


    The issue was also discussed at Microsoft Connect. Microsoft does not see this a bug and says registering an assembly to the GAC and using assemblies from the GAC during build is not recommended.