0

I have a local c# project that I have also checked into source control. This project builds and runs fine.

When I clone the project from source control and open it fresh in visual studio, it won't build because it can't find any of the classes in the Microsoft.ServiceBus.dll. I get for example 'The type or namespace name 'QueueClient' could not be found (are you missing a using directive or an assembly reference?)'

The source control project contains the identical packages.config to the local one that builds, but is missing the dll in the /bin/Debug/ folder after a build.

One difference I do see is that the reference property for that dll (solution explorer -> myproject -> references -> Microsoft.ServiceBus) has the 'Copy Local' value set to false, whereas in the project that builds (the one I checked in) this is set to true. However changing it in the properties pane doesn't work. It immediately flips back when I click away. Is this the issue? If so where does this bit of config live on the filesystem? (or how can I change it such that it persists in that file)?

EDIT: A bit more info: The solution has two projects: WorkerRole and TestHarness. Both projects have a dependency on the service bus, but there is only a packages.config file in the WorkerRole project, and in the cloned solution, the WorkerRole builds fine! So what did I do to get the packages.config to appear for WorkerRole?? I guess I did something slightly different to get the TestHarness to build in the local project!!

andrea
  • 481
  • 2
  • 8
  • 27

2 Answers2

2

Unable to change 'Copy local' on reference in visual studio (are you missing a using directive or an assembly reference?)

You need use the NuGet command line in the Package Manager Console:

Update-Package -reinstall

to force reinstall the package references into project.

Since you checked your project into source control, the default behavior of source control systems is Omit NuGet packages and bin folder in source control. When you clone the project from source control, those files are missing in your new clone project. So the 'Copy Local' value set to false. Although Visual Studio will restore nuget package automatically, NuGet Restore only restores files in the packages directory (\packages folder ), but does not restore files inside your project or otherwise modify your project.

Besides, NuGet does not prevent you from removing items added from packages, so it's easy to inadvertently modify contents installed from a package and break your project.

So, to resolve this issue, we need use the NuGet command line Update-Package -reinstall to force reinstall the package references into project after you clone project from source control with issue for references. See below link for more detail:

Nuget Packages are there but missing References

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thank you. Running Update-Package on the local project told me that 'No packages were found in packages.config for project 'TestHarness'. No package updates are available from the current package source for project 'TestHarness'.' So packages.config are missing for that project! I've updated my original question to also ask: How does packages.config get created?? – andrea Sep 29 '17 at 09:57
  • What`s project type of your "TestHarness"? Have you add any package to this project via NuGet? Once you add a package to a project via nuget, nuget will create package.config/project.json automatically. Since you are missing this file, you should check if you have this file before check "TestHarness" in source control. – Leo Liu Sep 29 '17 at 10:17
  • Are you add the dependency service bus manually, not using nuget? If you are use nuget to add this dependency, nuget will add packages.config automatically. – Leo Liu Sep 29 '17 at 10:24
  • Yes! I don't know what I'd done but removing the reference and readding through nuget worked! The packages.config file appeared and some other files changed. A push and a pull and the cloned project now builds! Thank you! – andrea Sep 29 '17 at 11:04
0

A few things here:

1) Git has a .gitignore file that appears in the root of your source-controlled solution folder. That excludes DLLs from being stored in source control. That's why you're missing the DLL in the cloned copy.

2) It seems that your reference to Microsoft.ServiceBus is the bin folder itself, which is why you can't set CopyLocal to true.

Remove your Microsoft.ServiceBus reference and add it back from the source folder, such as C:\Program Files (x86)\Windows Azure platform AppFabric\SDK\V1.0\Assemblies\NET4.0\Microsoft.ServiceBus.dll (if you don't see it there, scan your hard drive for a source copy). Once properly referenced, set Copy Local to true.

You should then be good to go.

Jazimov
  • 12,626
  • 9
  • 52
  • 59
  • Yes, the dll shouldn't be in source control. Some magic happens to get it in the cloned project on build. It's that process I guess I'm trying to understand a bit more. – andrea Sep 29 '17 at 09:46
  • My suggestions will work for people who struggle with a single DLL. Using NuGet is a sort of cop-out because it's not always clear what it did to fix a problem/issue. In your case, you learned that you were missing packages, and that's more involved than your original question indicated. Still, I hope my answer helps some people who have an issue with a single DLL. – Jazimov Sep 29 '17 at 13:03