Visual studio compile error - visual-studio-2010

I as using visual studio 2010. My solution is having more than one projects in it which are have relationships to each. When I adding a reference to a other project I can use public components (classes,enums ) of that. But when I compile it it gives error saying that those classes are not referenced(Not available).
But when I change the folder structure(When I reduce the level of folder hierarchy/when project folders borings to the root folder ex: d:\ ) it works fine.
Is it because of the length of the folder hierarchi ?

Check your namespaces
When you're adding reference, add it using Project References. So what it does is it compiles the dependencies first. Check if all projects are compiling individually.
Verify target framework versions

No, it is not because of folder hierarchy.... it is because not setting hierarchy properly !!
Follow this steps:
Lets say you have project A and project B.
Project A is dependent on Project B. So we need to add dependency of Project B to Project A.
So right click on Project A -> Open Folder in File Explorer.
Then check which folder it opens into (Lets call it "source folder") and check where the project files whose dependency to be added (Lets call it "destination folder") are located from that folder location. Add the relative path from source to destination folder. (Ex: "..\..\destination folder" ).
Add this relative path in Project A Properties -> Configuration Properties -> C/C++ ->Additional Include Directories.
Good luck.

Yes, hangar18 has suggested correctly. Add reference of each project (Static Libraries) to you execuatble project ( Console Application Project / Startup project).
Also add path of each folder where the header files and corresponding C/C++ files are residing.

Related

How can share code/files/folders between projects in same solution using Visual Studio?

How can copy all files and folders in 'Folder' from 'ProjectB' to 'ProjectA'
Solution
*ProjectA*
*ProjectB*
**Folder**
SubFolder
Files.extension
SubFolder
SubFolder
Files.extension
In visual studio i have created two different project in same solution.
I use AngularJS in both of projects, i have create some mine components for management data. Also i use AngularUI routing and i include all components as dependencies.
How can create a copy link for folder 'Folder' from 'ProjectB' that can include in 'ProjectA' ?
For now, i have duplicated all files, so if any change has been place in one project that include 'Folder', i must copy/paste folder 'Folder' to other project, so both projects have same files and code.
SOLUTION
In windows you can create linked folder from command prompt with this command 'mklink /D target source'. So any change to one file will bind to other always

How to have msbuild copy files to output directory across references?

Suppose we have a project A with output directory bin/ and a project B with output directory test/bin/. Project A needs to have a certain configuration file copied to its output directory. Currently, this is being done by adding a pre-build event that looks like
COPY /Y "$(ProjectDir)..\config.ini" "$(TargetDir)"
Project B has A as dependency. When project B builds, the binary resulting from A is correctly copied to the output directory of B, but the config file isn't!
How can we achieve that all files that A needs to have are also copied to the output directory of B?
What you want is a Link File. I've used these before to ensure that connection.config files are copied to multiple projects.
I created a sample solution that mimics your described scenario as seen below. The ConsoleApplication1 references the ClassLibrary1 project. In the solution, I created a solution folder config and added the shared config that needs to be copied.
In order to have a single file that is copied across multiple projects, you must create a single file, and then add it as a link to the projects that need it. This can be done by right clicking on the project, and choosing Add -> Existing Item.... You will see a dialog as show below and you want to choose the Add as Link option from the dropdown instead of just Add.
Finally, edit the properties for the linked file to copy it to the output directory.

Add shared library project's dll file to executable projects path at runtime in Eclipse

I'm using Eclipse Juno for c/c++ under Windows 7. I've created a shared library project and an executable project. I've added the shared library project as a reference in the executable project via:
executable project's properties -> C/C++ General -> Path and Symbols -> References -> check the shared library project
All this works great at compile time, I can include my shared library project's class in the executable project, and use it etc.
However when I try to run the executable project in Eclipse, I get nothing. No error, no console output. After some googling I've discovered a similar issue here:
http://www.eclipse.org/forums/index.php/m/650331/
Apparently adding the shared library project to the executable project in Eclipse, as described above, does NOT also add the dll file to the executable (.exe) file's PATH at run time inside Eclipse. As an analogy with Eclipse for Java: if you have a Java JAR project A and another Java JAR project B, by making a reference from B to A in Eclipse, B's compiled jar file IS added to A's class path when running project A inside Eclipse. I thought it would be similar with Eclipse for C/C++ but apparently it's not.
Sure enough, if I manually take the .exe file and the .dll file, place them in the same folder and run the .exe, everything works ok. Also if I copy the .dll file in to Eclipse's compilation directory for the executable project, I can run the executable project from Eclipse and it's ok.
My question is then, is there a way to have Eclipse add that shared library project's dll file to the run time when I'm telling it to run the executable project? The discussed solution in the post I link to above is to manually add the shard library project's compile directory to the Eclipse's run configuration for the executable project, namely, to add it to the PATH variable there. But I find this cumbersome and not portable, if Eclipse is managing both projects it should be able to pass all that's necessary to the run time.
Well, I've went with the manual adding of the library project's dll to the excutable project's path at run time. I did find a way to make it more portable and project location neutral (i.e. if you move both projects' source folders to another machine, and reopen them in Eclipse there, it should still work):
right click on executable project -> Run as... -> Run Configurations
in the Environment tab click "New..." to add a new environmental variable
Name your variable "PATH" and give it a value similar to this:
${env_var:PATH};${workspace_loc:/cppAStar/Debug}
where:
${env_var:PATH} is Eclipse's way of saying "get the already existing value of the PATH environmental variable as declared in Eclipse"
the ";" is to separate the exisitng PATH entries from the new one we're about to add
${workspace_loc:/cppAStar/Debug} this tells Eclipse to get the location of the workspace project named cppAStar (here cppAStar is my shared library project) and then the "/Debug" refers to where this particular project creates the .dll file when it's built.
Issues that I couldn't figure out:
the "Environment" tab in "Run configuration" has an option called "Append environment to native environment". I thought that by checking this I'd only need to add the location of the .dll dir in the PATH variable I declare here, and it will be appended to the existing PATH. However I've not managed to make this work, hence the manual re-adding of all the existing PATH before appending the new value
Unfortunately that solution does not work for the debugg configuration. See Bug 338420 -Launch configuration's Environment tab variables are not passed to the gdb process itself.
Is there a way to solve this problem for debugging? I mean except from doing post-build steps like:
cmd /c copy "${BuildArtifactFilePrefix}${BuildArtifactFileName}" "${WorkspaceDirPath}\bin\"

When trying add existing project to solution, a project in a different path is referenced

I am doing some housecleaning with our VC++ project structure and I had the following weird directory setup. In one folder, called "USBAScan", I have a Visual C++ project file, named "USBAScan.vcxproj". USBAScan has a subfolder that is also called "USBAScan". It also has a VC++ project file named "USBAScan.vcxproj".
My VC++ solution references a project named "USBAScan.vcxproj". Its project file property is "USBAScan\USBAScan\USBAScan.vcxproj". I remove this project and delete the project file USBAScan\USBAScan\USBAScan.vcxproj. In the solution I try to add USBAScan\USBAScan.vcxproj. I get the following error message:
"The project file USBAScan\USBAScan\USBAScan.vcxproj has been moved, renamed or is not on your computer".
Although I'm trying to add USBAScan\USBAScan.vcxproj, the solution is trying to add USBAScan\USBAScan\USBAScan.vcxproj. Why would it behave this way?

Visual Studio Test Project - Does not copy folder on deployment

Here is the problem:
1. Create a TestProject in your Visual Studio solution.
2. Open the .testrunconfig file and under the 'deployment' menu item, select the 'Enable Deployment' checkbox.
3. Now click on 'Add Directory...' button and add a folder which has some files in it.
4. Run the test project (use a dummy test).
Ok, now go check the TestResults folder: You will see that all the files got directly copied (to the top level)- the folder itself is not copied (with the files under them). This messes up my paths during testing. Can anybody tell how to get the folder copied instead of just the files underneath ?
Thanks.
Use the [DeploymentItem] attribute on the test classes that use it. You can specify a directory:
[TestClass]
[DeploymentItem("blahblah\\myDirectory", "myDirectory")]
public class MyTest
{
}
Note:
DeploymentItem is very slow when starting the tests. It seems to copy 2 files per second.
You can specify the attribute on a test base class. But it does not always work if you have more than one test project.
You can probably specify it on a TestClass that has a method marked with [AssemblyInitialize]. Then you have only to provide it once. Not sure, you have to try.
The source directory is relative to the solution location. This is hardly documented.
Open the .testsettings file in notepad. Now, you should see that for every folder to copy
<DeploymentItem filename="FolderName\" />
Change this to
<DeploymentItem filename="FolderName\" outputDirectory="FolderName\" />
The other option you have is to create another folder beneath the original folder, and then that folder will be deployed to the out directory. For example you can have this structure:
TestFolder/
TestFolder/TestDeployment/
And then in the testrunconfig you still select the TestFolder folder and the TestDeployment folder will be deployed to the out directory.
I just had this problem too today. I solved it by adding a folder called "deployment_files" in the project that contained the required folder. Then I put the required folder into the "deployment_files" folder. THEN, I opened the LocalTestRun.testrunconfig file under the "Solution Items" folder in the Solution Explorer. Went to the "Deployment" panel in the testrunconfig property window. Added the "deployment_files" directory to the deployment and voila. The folder within that was copied to the test results Out folder.

Resources