Visual Studio referenced assembly CopyLocal doesn't work - visual-studio-2010

I have a Console application and a Class Library in a solution. Whenever I reference class library from console application it finds it but after building the solution it cannot find the type.
Although CopyLocal is set to true but the referenced assembly is not copied !

The reason was my console application target framework was Client Profile. Changing it to .NET 4.0 resolved the problem.

Is the referenced assembly in the Global Assembly Cache? Assemblies that are installed in the GAC are not copied to the output folder, even when CopyLocal is true.

Related

VS2015 - debug my referenced project

I have a solution using to projects: a class library project, and a console application referencing this. Now when I try to debug the console application, it loads the class library from the GAC, not the version from the "sister project" of the solution. I just have changed one line of code in the class library project, and the debugger now just shows me the disassembly instead of the C# source code for methods in the class library.
How can I get VS2015 to load the assembly version from the sister project, not the version from the GAC?
If the same dll file was in the GAC, it would be loaded firstly, I think it is the reason why it ignored the reference project. So if you really want to use the project reference, you really need to remove the GAC.
Of course, other members also provided the suggestion like using the version numbers:
https://social.msdn.microsoft.com/Forums/en-US/af5086ad-a2b6-4707-b593-0ca4f5518a6a/force-use-of-local-assembly-instead-of-gac?forum=clr

Visual Studio Solution DLL error

I have a visual studio solution which works fine on one machine and when I copy the complete same solution to another machine it misses few external dlls.
Both the machine have same configuration and same version of visual studio.
I tried removing reference and adding again.I am able to reference the dll and use code but when I re-build,It gives the same error.Any pointers on what could have gone wrong?
The error message I get is as below
The type or namespace name 'NameSpaceName" could not be found (are you missing a using directive or an assembly reference?)
Also the warning shows.
The primary reference "NameSpaceName" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
Both the machine have Visual Studio 2010 installed. It works on one and doesn't work on another machine
The reference you have added to the project is likely not in a subfolder of your project but referenced from the Global Assembly Cache (GAC). Since you probably didn't copy the GAC, this reference is now of a different version. Figure out which (3rd party ?) component is affected and install an older version of that component.
Typically, Visual Studio cannot target .NET 4.5, unless you applied a workaround. In that case, you can go to the project properties, Application and change Target Framework from 4.0 to 4.5.

Visual Studio Team Services Build Issues

I am using Visual Studio Team Services as source control and have enabled continuous integration.
My project is an ASP.NET application which used Entity Framework 5. When i checkin the code and the build controller tries to build it, the following errors come up
DataModel\GenomicsTutorDataModel.Context.cs (40): The type or
namespace name 'DbSet' could not be found (are you missing a using
directive or an assembly reference?)
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets
(1578): Could not resolve this reference. Could not locate the
assembly "EntityFramework". Check to make sure the assembly exists on
disk. If this reference is required by your code, you may get
compilation errors.
In my solution i have made system.data.entity CopyLocal = True yet no success.
Any ideas?
May be you are on a 64 bits machine and the TFS server is not?
Try to build your project for Any CPU or x86.
Add the DLL you referenced for System.Data.Entity into a folder in your project or somewhere in a folder in the Source Control and reference to that one. Check this in and try to build your application again.

How to reference assembly from GAC?

I have installed the strong named assembly TestReflection into the GAC (I am using .NET 4.0 and VS 2010).
Different versions of the TestReflection DLL are in GAC of .NET 4.0 (C:\WINDOWS\Microsoft.NET\assembly\GAC_32\TestReflection\), however, the assembly does not appear in the "Project" -> "Add reference" box of VS 2010.
How can I refer to my assembly deployed in GAC at design time from another project?
This page says that:
You cannot add references from the Global Assembly Cache (GAC), as it is strictly part of the run-time environment.
Referring to this statement, I would like to know how to make your project's DLL shared assembly for other consumers if it's the requirement?
The dll's shown in the .Net tab of the "Add references" dialog are not actually the ones registered in the GAC. They are found by searching a few paths on your filesystem.
The paths being searched are located by Visual Studio by looking up the following registry entries:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NetFramework\{Version}\AssemblyFoldersEx\
There should be some keys added there already, so if you want your own dll to show up on the .Net tab, you can add it to one of the folders defined there. You could also add a new registry key pointing to a custom folder, which would only contain your own dll's.
The GAC is only meant for loading assemblies at runtime after your application has been deployed, so I don't think you should use it while developing. When you deploy your app, make sure to set "Copy local" to false on your reference so the dll won't be copied to the bin folder, and then install it into the GAC and it will be loaded from there instead.
Another simple option would be to manually edit the project file as XML in visual studio (You will have to unload the project first), and simply add node <Reference Include="<name of dll>" /> in MSBuild project file. After reloading the project, VS will pick up the reference without problem.
If you want to add Global Assembly Cache references to your VS2010 project, there is an extension you can use: Muse.VSExtensions.
It has some quirks but does a decent job. Check it out...
The answer is the Reference Paths in the property windows, you have to set it with the GAC path
Please see my post here:

VS2005: Assembly '<assembly>' is incorrectly specified as a file.

I've added a reference to the log4net assembly dll to my project.
When I build I get a warning saying:
Warning Assembly 'Lib\log4net.dll' is
incorrectly specified as a file.
I look up the help for this error on MSDN, and it says:
This warning is generated during
application manifest generation when
the build process detects that a file
reference is actually a (managed or
native) assembly.
This is exactly what I'm doing; the file reference is an assembly. What am I being told here?
How do I add a reference to an assembly dll, while not adding a reference to an assembly dll?
Try setting the Build Action property of the source DLLs to None. It solved the issue for us.
I was running into this problem myself.
This is what worked for me:
I had added an assembly as a reference and as an "Existing Resource." Deleting the file from the Solution Explorer, closing, then reopening the project worked.

Resources