I have solution A (which has the startup project) and solution B. Solution A uses things from solution B. For that A has a project which when rebuilt copies dlls and .pdbs to A's directories. Is there a way to make solution A recognize source code that sits in B? For example if I have a class moo in B, can I accomplish the following?
Have Intellisense in solution A be aware of type moo and moo's methods, including recommending it when trying to instantiate a new object?
Be able to F12 the moo type from solution A and have visual studio open the original source code for me just like types that originate from solution A?
Can I access source code sitting in a different solution in Visual
studio (.net/C#)
To debug the projects of Solution B in Solution A, you should make sure that you have xx.dll and xx.pdb files from Solution B are on the outputpath folder of Solution A.
Just as Hans said, you can right-click on Solution A -->Add-->Existing Project-->select the related xxx.csproj of Solution B.
After that, Click on References of the project from Solution A --> Add Reference--> Projects--> select the target imported project from Solution B.
With them, you could debug that project and enter into B's code in Solution A.
=================
Besides, if the project of the solution B is a class library project, you could also use Add Reference node on the project of Solution A to reference the target xxx.dll.
Right-click on the project-->Add Reference-->Browse-->find the output file xxx.dll of the Solution B in the new instance.
Please note you should use Debug Configuration to build them all.
Then you can use it in your project.
In addition, you could also use ProjectReference xml node in xxx.csproj file of Solution A.
Add these in xxx.csproj file:
<ItemGroup>
<ProjectReference Include="xxxx\SolutionB\xxxx.csproj"> // the path of the project in Solution B
<Name>xxxxx</Name> //name of the project
</ProjectReference>
</ItemGroup>
Then build your project once and then you can get it.
Although there is a warning the referenced component xxx cannot be referenced, vs can still find the referenced project and use its content.
In few words
My question is: Is there a way for generating a visual studio solutions that contains a project, for which I'm writing the CMake, and another project, for which the CMake is already available?
I was thinking about using add_subdirectory, but I'm not sure this is the best solution and the meaning of the parameter binary_dir is not really clear to me.
More in details
I have a Visual Studio project (B) which depends on another one (A).
I've written the CMakeLists for A and I'm able of generating the VS project and compiling it.
I've written a CMakeLists for B. I'm able to configure the VS project for B in such a way that it can access the headers and the libraries of A. Everything compiles.
A
- CMakeLists.txt
- src
- *.cpp
B
- CMakeLists.txt
- src
- *.cpp
Build
- Build_A
- Build_B
However when I change something in A, from the B project (that's possible because with visual studio I can access the headers of A from the project B), and I try to compile, A is not compiled.
The project B compiles only B.
I was able to improve the situation by using add_subdirectory. In the CMakeLists of B I included the following line:
add_subdirectory(PATH_TO_A A)
However with this solutions there is a duplication of the compilation files of A. They are generated in the out-of-source build directory BUILD_A when I compile from the project A; and they are generated in the out-of-source build directory BUILD_B\A when I compile from the project B.
What's the best practice for including the A project in the solution generated from the CMakeLists of B and avoid duplication of compilation files?
P.S.
If possible I would like to avoid the need of recompiling everything twice. That is, If I have compiled A and I need to compile B for the first time I would like to avoid the need of recompiling A.
In principle using add_subdirectory is a good way to solve this.
A CMake project that can be compiled on its own can also be compiled as a subproject, if it follows a few rules. First of all, any change to the global state will of course also affect all other projects being built from the same root. Aggressive changes to the global build environment are likely to disturb other projects and should be avoided.
Additionally, a project that is being pulled in like this must not assume that its CMakeLists file is the root of the build. For instance, the CMAKE_BINARY_DIR variable always points to the top-level binary directory, while the PROJECT_BINARY_DIR points to the binary directory of the most recent project. A library that always assumes it's being built as a top-level binary may use those two interchangeably. A library that can be built both on its own or as a sub-project must be aware of the difference.
Note that add_subdirectory introduces a tight coupling between the projects and only works well if both involved projects behave accordingly.
A more loosely coupled alternative would be to include the dependency as an ExternalProject, but from what you wrote in the question (project should automatically recompile if source of the dependency changes), add_subdirectory seems the better match for you.
I have 2 c++ projects in a solution.
ExecB (an executable) depends on ProjA (a dll).
So in ExecB's properties I add ProjA as a reference, and select Copy Local = true.
The problem is, ProjA's dll isn't being copied to ExecB's output folder folder. So the executable obviously doesn't run.
Any suggestions ?
For C++ projects, the Visual Studio template/wizard sets the Output Directory to a subfolder of the solution: $(SolutionDir)$(Configuration)\. This is so the DLL Search Path works well for the developer. It even works if you have added projects to the solution from outside the solution folder hierarchy; The build will put all binaries into the output folder for that solution.
If this isn't working, check the Output Directory property on all platform/configuration combinations of all your projects. Also make sure that the Build Configuration Manager shows that your selected solution build is building all the projects appropriate for the solution platform/configuration.
The Copy Local in Project References that you are trying applies only to referenced .NET assemblies. The docs are ambiguous and too terse on that. (Most often undistinguished use of "assembly" means .NET assembly rather than WinSxS assembly.)
I am working on setting up a buildserver for our team.
Background
We are using Microsoft Visual Studio 2010 Ultimate. Our product contains C# code(mainly), external DLL’s and C code. We are working with .Net 4.0 and have more than 70 projects.
We are working with 3 branches of our code:
Production branche(what is currently released)
Test branche(hot fixes, bug fixes, end user testing)
Development branche(adding new fetures)
All the branches are under TF source control.
Goal
What we want is to have a build server to build and run all the unit tests for all the branches once a day, the build server should use the code in the source control. Our goal is to have some fast standard error detection. We would prefer as little to no maintaining of the build server.
We are not going to use the builds the buildserver produce, all we want is to use the build server to continuously to build and unit test our branches.
What is set up
There are currently set up two the build definition, one for the Test Branche and one for the Development Branche, both build definitions taking the code from the source control(that part works all good), but here is where the fun begins.
Problem
The Test Branche can build and run unit tests all fine.
The Development Branche cannot build due to an(or like 5 of) errors:
The type or namespace name 'XXX' does not exist in the namespace 'YYY' (are you missing an assembly reference?)
The error is for project X refereing to project Y. Both project X and Y is C# .Net 4.0 projects and we have fully control over both of them, both X and Y is compiled to DLL’s. Project Y contains a Interface the classes in project X are implementing.
The annoying detail is there is no difference in the Test Branche and Development Brance for either project X or Y. The two projects have been fully identical the last 3 month.
So the question is, why does it work in the Test Branche but not in the Development branche?
I have tested:
- The projects are correctly refered to each other.
- All 3 Branches have no problem building on my own / any of my co-workers development machines(we have tested on 5 different machines).
- I have tried to delete the whole X project and recreate it, didn’t work.
- I have tried to delete the whole Y project and recreate it, didn’t work.
- I have tried to change the namespace for project X project and its classes, didn’t work.
- I have tried to change the namespace for project Y project and its classes, didn’t work.
- (I have even restarted my development machine)
- All the changes have always been checked into the source control where after the buildserver was set to build.
Extra information
I have been digging around in the logging files and found some interessting details, this is for the details of building project X in the Development Branche
Task "AssignProjectConfiguration"
Project reference "..\..\A" has been assigned the "Debug|x86" configuration.
Project reference "..\..\Y" has been assigned the "Debug|x86" configuration. (can see there is a project Y)
Project reference "..\..\B" has been assigned the "Debug|x86" configuration.
But then in the Task ”ResolveAssemblyReference”
Task "ResolveAssemblyReference"
TargetFrameworkMoniker:
.NETFramework,Version=v4.0
TargetFrameworkMonikerDisplayName:
.NET Framework 4
TargetedRuntimeVersion:
v4.0.30319
Assemblies:
System
System.Xml.Linq
System.Data.DataSetExtensions
Microsoft.CSharp
System.Data
System.Xml
System.Core
AssemblyFiles:
C:\Builds\1\A
C:\Builds\1\B
(----- Missing project Y -----)
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll
Where in the Test Brance for the same task
Task "ResolveAssemblyReference"
TargetFrameworkMoniker:
.NETFramework,Version=v4.0
TargetFrameworkMonikerDisplayName:
.NET Framework 4
TargetedRuntimeVersion:
v4.0.30319
Assemblies:
System
System.Data.Entity
System.Xml.Linq
System.Data.DataSetExtensions
Microsoft.CSharp
System.Data
System.Xml
System.Core
AssemblyFiles:
C:\Builds\1\A
C:\Builds\1\B
C:\Builds\1\Y (There it is)
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll
So it feels like it for some reason just ”forgets” the reference from project X to project Y.
Help
I had the same problem.
It took me few hours to find out that in this case the problem was not my fault :-)
http://support.microsoft.com/kb/2516078 :
This issue occurs due to a bug in the Path.GetFullPath in .NET Framework library.
This is a known issue in Visual Studio 2010
Symptoms:
... when you try to build a solution with multiple
projects where there exists dependency relationships among them, in
specific conditions a build fails with the following error message.
Error Message:
“C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets
(1200, 9): warning: The referenced project 'Relative path to the
referenced project from the current directory’ does not exist.”
A build fails with the error message above when the following
conditions are met.
You have a solution with multiple projects where there exists dependency relationships among them.
The sum of the following two path length is exactly added up to 259 characters (= MAX_PATH – 1)
1) The path of a referencing project’s directory. 2) The relative path
to a referenced project from the current directory (= a referencing
project’s directory).
NOTE: MAX_PATH is the maximum path length defined by Windows API and
is set to be 260 characters.
Workaround:
To work around this issue, you can change path length and make sure
that the sum of the following two path length is NOT added up to 259
characters.
The path of a referencing project’s directory.
The relative path
to a referenced project from the current directory (= a referencing
project’s directory).
I encountered the same error recently. The solution built locally in VS2010 just fine, but consistently failed on the build server. In the end, the MSBuild definition was set to the Release x86 configuration, but the complaining project referenced an assembly in bin\x86\Debug, instead of bin\x86\Release.
Verifying the release version of the assembly was referenced instead of the debug version (and correcting as needed) seemed to do the trick for me.
The problem on my end was entirely different unfortunately.
I was building two different versions of the same common code, one for .Net4 and another for Silverlight 5, with the same file name (.Framework.dll).
Since the build server outputs everything to the same folder by default, the Silverlight version of the assembly ended up overwriting the .Net4 one because msbuild decided to build it later. This caused a problem as soon as the next project in the solution was built, which was dependent on some classes that were available on the .Net4 version of the dll, but not on the Silverlight one.
I ended up splitting the projects in multiple solutions and setting the 'Solution Specific Build Outputs' option to true on the build definition 'Process' tab.
I had a very similar issue. I found that in the Configuration Manager, under the Release Configuration, the platform was set to Any CPU and the Build checkbox was not checked.
Setting the platform to x86 (as all my other projects are set to this for legacy reasons) and making sure the project was set to Build under this configuration fixed my issue.
I've just had a similar issue and it ended up being the developer who last worked on the code decided to add references to some dlls in the obj\debug directory.
It is a bit old question but I've just come across similar issue and in my case it was the wrong referenced project Id (let's call it B) in the .cproj file of the project that was failing (project A). Originally, I copied the project A from another solution and included it in the solution I am working with now. The referenced project B was also present in both solutions so Visual Studio automatically resolved references even though in the A's .cproj referenced project B was still pointing to the B in the solution I copied it from:
<ProjectReference Include="..\B.csproj">
<Project>{F3006530-D421-4A89-AA8B-376DBAA31E03}</Project> - wrong Id!
<Name>ProjectB</Name>
</ProjectReference>
Weirdly, Visual Studio would ignore the incorrect Id and presumably use the path only so there were no build errors and correct dll would appear in project A's bin. MSBuild on my build server wouldn't be that liberal though.
To fix it you can either edit .cproj file in a text editor or simply remove references and add them back making sure they're in your current solution.
I have four projects in my Visual Studio solution (everyone targeting .NET 3.5) - for my problem only these two are important:
MyBaseProject <- this class library references a third-party DLL file (elmah.dll)
MyWebProject1 <- this web application project has a reference to MyBaseProject
I added the elmah.dll reference to MyBaseProject in Visual studio 2008 by clicking "Add reference..." → "Browse" tab → selecting the "elmah.dll".
The Properties of the Elmah Reference are as follows:
Aliases - global
Copy local - true
Culture -
Description - Error Logging Modules and Handlers (ELMAH) for ASP.NET
File Type - Assembly
Path - D:\webs\otherfolder\_myPath\__tools\elmah\Elmah.dll
Resolved - True
Runtime version - v2.0.50727
Specified version - false
Strong Name - false
Version - 1.0.11211.0
In MyWebProject1 I added the reference to Project MyBaseProject by:
"Add reference..." → "Projects" tab → selecting the "MyBaseProject". The Properties of this reference are the same except the following members:
Description -
Path - D:\webs\CMS\MyBaseProject\bin\Debug\MyBaseProject.dll
Version - 1.0.0.0
If I run the build in Visual Studio the elmah.dll file is copied to my MyWebProject1's bin directory, along with MyBaseProject.dll!
However if I clean and run MSBuild for the solution (via D:\webs\CMS> C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /t:ReBuild /p:Configuration=Debug MyProject.sln)
the elmah.dll is missing in MyWebProject1's bin directory - although the build itself contains no warning or errors!
I already made sure that the .csproj of MyBaseProject contains the private element with the value "true" (that should be an alias for "copy local" in Visual Studio):
<Reference Include="Elmah, Version=1.0.11211.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\mypath\__tools\elmah\Elmah.dll</HintPath>
**<Private>true</Private>**
</Reference>
(The private tag didn't appear in the .csproj's xml by default, although Visual Studio said "copy local" true. I switched "copy local" to false - saved - and set it back to true again - save!)
What is wrong with MSBuild? How do I get the (elmah.dll) reference copied to MyWebProject1's bin?
I do NOT want to add a postbuild copy action to every project's postbuild command! (Imagine I would have many projects depend on MyBaseProject!)
I just deal with it like this. Go to the properties of your reference and do this:
Set "Copy local = false"
Save
Set "Copy local = true"
Save
and that's it.
Visual Studio 2010 doesn't initially put:
<private>True</private> in the reference tag and setting "copy local" to false causes it to create the tag. Afterwards it will set it to true and false accordingly.
I'm not sure why it is different when building between Visual Studio and MsBuild, but here is what I have found when I've encountered this problem in MsBuild and Visual Studio.
Explanation
For a sample scenario let's say we have project X, assembly A, and assembly B. Assembly A references assembly B, so project X includes a reference to both A and B. Also, project X includes code that references assembly A (e.g. A.SomeFunction()). Now, you create a new project Y which references project X.
So the dependency chain looks like this: Y => X => A => B
Visual Studio / MSBuild tries to be smart and only bring references over into project Y that it detects as being required by project X; it does this to avoid reference pollution in project Y. The problem is, since project X doesn't actually contain any code that explicitly uses assembly B (e.g. B.SomeFunction()), VS/MSBuild doesn't detect that B is required by X, and thus doesn't copy it over into project Y's bin directory; it only copies the X and A assemblies.
Solution
You have two options to solve this problem, both of which will result in assembly B being copied to project Y's bin directory:
Add a reference to assembly B in project Y.
Add dummy code to a file in project X that uses assembly B.
Personally I prefer option 2 for a couple reasons.
If you add another project in the future that references project X, you won't have to remember to also include a reference to assembly B (like you would have to do with option 1).
You can have explicit comments saying why the dummy code needs to be there and not to remove it. So if somebody does delete the code by accident (say with a refactor tool that looks for unused code), you can easily see from source control that the code is required and to restore it. If you use option 1 and somebody uses a refactor tool to clean up unused references, you don't have any comments; you will just see that a reference was removed from the .csproj file.
Here is a sample of the "dummy code" that I typically add when I encounter this situation.
// DO NOT DELETE THIS CODE UNLESS WE NO LONGER REQUIRE ASSEMBLY A!!!
private void DummyFunctionToMakeSureReferencesGetCopiedProperly_DO_NOT_DELETE_THIS_CODE()
{
// Assembly A is used by this file, and that assembly depends on assembly B,
// but this project does not have any code that explicitly references assembly B. Therefore, when another project references
// this project, this project's assembly and the assembly A get copied to the project's bin directory, but not
// assembly B. So in order to get the required assembly B copied over, we add some dummy code here (that never
// gets called) that references assembly B; this will flag VS/MSBuild to copy the required assembly B over as well.
var dummyType = typeof(B.SomeClass);
Console.WriteLine(dummyType.FullName);
}
If you are not using the assembly directly in code then Visual Studio whilst trying to be helpful detects that it is not used and doesn't include it in the output. I'm not sure why you are seeing different behaviour between Visual Studio and MSBuild. You could try setting the build output to diagnostic for both and compare the results see where it diverges.
As for your elmah.dll reference if you are not referencing it directly in code you could add it as an item to your project and set the Build Action to Content and the Copy to Output Directory to Always.
Take a look at:
This MSBuild forum thread I started
You will find my temporary solution / workaround there!
(MyBaseProject needs some code that is referencing some classes (whatever) from the elmah.dll for elmah.dll being copied to MyWebProject1's bin!)
I had the same problem.
Check if the framework version of your project is the same of the framework version of the dll that you put on reference.
In my case, my client was compiled using "Framework 4 Client" and the DLL was in "Framework 4".
The issue I was facing was I have a project that is dependent on a library project. In order to build I was following these steps:
msbuild.exe myproject.vbproj /T:Rebuild
msbuild.exe myproject.vbproj /T:Package
That of course meant I was missing my library's dll files in bin and most importantly in the package zip file. I found this works perfectly:
msbuild.exe myproject.vbproj /T:Rebuild;Package
I have no idea why this work or why it didn't in the first place. But hope that helps.
I just had the exact same problem and it turned out to be caused by the fact that 2 projects in the same solution were referencing a different version of the 3rd party library.
Once I corrected all the references everything worked perfectly.
As Alex Burtsev mentioned in a comment anything that’s only used in a XAML resource dictionary, or in my case, anything that’s only used in XAML and not in code behind, isn't deemed to be 'in use' by MSBuild.
So simply new-ing up a dummy reference to a class/component in the assembly in some code behind was enough convince MSBuild that the assembly was actually in use.
Using deadlydog's scheme,
Y => X => A => B,
my problem was when I built Y, the assemblies (A and B, all 15 of them) from X were not showing up in Y's bin folder.
I got it resolved by removing the reference X from Y, save, build, then re-add X reference (a project reference), and save, build, and A and B started showing up in Y's bin folder.
Changing the target framework from .NET Framework 4 Client Profile to .NET Framework 4 fixed this problem for me.
So in your example: set the target framework on MyWebProject1 to .NET Framework 4
I had the same problem and the dll was a dynamically loaded reference.
To solve the problem I have added an "using" with the namespace of the dll.
Now the dll is copied in the output folder.
This requires adding a .targets file to your project and setting it to be included in the project's includes section.
See my answer here for the procedure.
Referencing assemblies that are not used during build is not the correct practice. You should augment your build file so it will copy the additional files. Either by using a post build event or by updating the property group.
Some examples can be found in other post
MSBuild to copy dynamically generated files as part of project dependency
VS2010 How to include files in project, to copy them to build output directory automatically during build or publish
Another scenario where this shows up is if you are using the older "Web Site" project type in Visual Studio. For that project type, it is unable to reference .dlls that are outside of it's own directory structure (current folder and down). So in the answer above, let's say your directory structure looks like this:
Where ProjectX and ProjectY are parent/child directories, and ProjectX references A.dll which in turn references B.dll, and B.dll is outside the directory structure, such as in a Nuget package on the root (Packages), then A.dll will be included, but B.dll will not.
I had a similar issue today, and this is most certainly not the answer to your question. But I'd like to inform everyone, and possibly provide a spark of insight.
I have a ASP.NET application. The build process is set to clean and then build.
I have two Jenkins CI scripts. One for production and one for staging. I deployed my application to staging and everything worked fine. Deployed to production and was missing a DLL file that was referenced. This DLL file was just in the root of the project. Not in any NuGet repository. The DLL was set to do not copy.
The CI script and the application was the same between the two deployments. Still after the clean and deploy in the staging environment the DLL file was replaced in the deploy location of the ASP.NET application (bin/). This was not the case for the production environment.
It turns out in a testing branch I had added a step to the build process to copy over this DLL file to the bin directory. Now the part that took a little while to figure out. The CI process was not cleaning itself. The DLL was left in the working directory and was being accidentally packaged with the ASP.NET .zip file. The production branch never had the DLL file copied in the same way and was never accidentally deploying this.
TLDR; Check and make sure you know what your build server is doing.
Make sure that both projects are in the same .net version also check copy local property but this should be true as default
Using Visual Studio 2015 adding the additional parameter
/deployonbuild=false
to the msbuild command line fixed the issue.
I just ran into a very similar issue. When compiling using Visual Studio 2010, the DLL file was included in the bin folder. But when compiling using MSBuild the third-party DLL file was not included.
Very frustrating. The way I solved it was to include the NuGet reference to the package in my web project even though I'm not using it directly there.
I dont think #deadlydog answer is valid with the current Nuget system. I recreated the scenario with Y => X => A => B in visual studio 2022 and all I had to do was run the command in terminal
msbuild -t:clean,rebuild,pack
Including all referenced DLL files from your projectreferences in the Website project is not always a good idea, especially when you're using dependency injection: your web project just want to add a reference to the interface DLL file/project, not any concrete implementation DLL file.
Because if you add a reference directly to an implementation DLL file/project, you can't prevent your developer from calling a "new" on concrete classes of the implementation DLL file/project instead of via the interface. It's also you've stated a "hardcode" in your website to use the implementation.