Reputation: 26331
We're using Visual Studio 2010 and we recently started using Google API. Due to irrelevant reasons, we cannot use NuGet Package Manager for handling dependencies. Instead, what we did was something similar.
We created a libraries
folder in our solution root so all our projects would reference the same libraries, pretty much what NuGet does, but without the Package Restore or the ease to update.
We added the following references to our project:
Along with the appropiate dependencies:
However, when trying to compile my project, the following error shows up:
The type or namespace name 'Apis' does not exist in the namespace 'Google' (are you missing an assembly reference?)
The strange thing is that right after my building fails, IntelliSense won't detect any Apis
namespace, just as the compiler is telling me.
But if I remove the dependency and add it again, then it finds it.
After this point, if I try to compile the project again, the process would fail, and IntelliSense would (again) fail to find the Apis
namespace.
We already tried deleting temporary files, but with no luck.
What may be happening?
I began to notice some warnings:
The primary reference "System.Net.Http.Extensions" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework, Version=4.0". To resolve this problem, either remove the reference "System.Net.Http.Extensions" or retarget your application to a framework version which contains "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
I am currently targeting .NET v4, and I indeed have the System.Net.Http
assembly being referenced from the project.
The same warnings shows up for the following assemblies:
My System.Net.Http
is version 2.2.28.0, which explains the warning, because System.Net.Http.Extensions
is looking for version 1.5.0.0.
This led me to create the following app.config
which should remove the version conflicts:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.13.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The same errors and warnings appear.
Upvotes: 2
Views: 1717
Reputation: 1477
The problem seems to be with assembly redirect in class library projects. It doesn't happen when using NuGet, since NuGet adds Microsoft.Bcl.Build.target file that redirects the DLLs (see this question for more details).
There seems to be 3 possible solutions to this:
Download the DLLs and reference them in a class library, and do the following:
Copy locally the package Microsoft.Bcl.Build.1.0.14, and add the following to your class library csproj:
<Import Project="..\PACKAGE_LOCATION\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\PACKAGE_LOCATION\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
(Replace PACKAGE_LOCATION with the location of the Microsoft.Bcl.Build.1.0.14 package)
If other projects reference your class library, you will then get an error:
warning : All projects referencing MyProject.csproj must install nuget package Microsoft.Bcl.Build
To solve that you'll have to add the DLLs and the Microsoft.Bcl.Build.targets to all the referencing assemblies (see this for more information).
Hope this helps.
Upvotes: 1