In Visual Studio, how do I include a built file in another project? - visual-studio

How specifically should my command line be written as to copy the output from one project into the output of another project? The list of macros that are avaliable does not list anyway of accessing OTHER project directories under the same solution:
http://msdn.microsoft.com/en-us/library/42x5kfw4(v=vs.80).aspx
Here is what I currently have:
copy "$(TargetDir)FILE_TO_MOVE.EXE" ""
What should I put in the second quote to complete this command?
NOTE: A similar question does NOT actually show you HOW to do it, which is what I am asking: Visual Studio 2008: How do I include project output as an embedded resource in another project?

It is much easier to do it the other way around, have the project that has the dependency on the file also copy the file. Which you can do in the IDE without pre/post buid event or macro trickery.
Ensure the source project is built. Right click the target project, Add Existing Item and select the file. Click the added file in the Solution Explorer window and set the properties to Build Action = Content, Copy to Output Directory = Copy if newer. And right-click the target project, Project Dependencies, tick the source project to ensure that it always gets built first.

I am assuming that yout are copying the "FILE_TO_MOVE.EXE" in the post build events of your project.
The thing about the build events in Visual Studio is that they are run just like a batch file, therefore I beileve that the easiest way to solve your problem is to use a system environment variable in your project... This way your code would be similar to the one below.
copy "$(TargetDir)FILE_TO_MOVE.EXE" "$(MyVariable)"
Note: Visual Studio doesn't let you use your environment variable like this: %MyVariable%.

I think the correct way now would be to simply add your secondary project, i.e a Windows Service, to the References of the main project.
For example if you have a main GUI project (that the solution was created with), and a second Service project added to the solution, adding it to References of the GUI project will cause the EXE and the PDB of the service to be placed in the Debug/Release folder of you main project.
I am not sure if you still need to add the Project Dependancy as Hans suggested . This is probably automatic thanks to the reference.

Related

How can I move common code into external assembly to be used in Unity 3d projects?

I have to share some code between multiple projects in Unity. This code is under constant changes during work on projects. So I need my code to be shared as separate assembly and be included in each Unity solution in Visual Studio 2015.
What is the way to make changes in common assembly so that it automatically updates for other projects and for Unity editor?
Your solution is in submodules with version control. You have one repo for the main project. Then you have a folder within that is another repo. This one is a submodule. It appears grey on your main repo and does not go into commit.
https://git-scm.com/book/en/v2/Git-Tools-Submodules
It does work with other version control systems.
The point of that pattern is that you work on project A with utility-submodule. utility is a folder inside Assets folder. Then you modify Utility.cs and push it on Utility repo.
Project B is using utility-submodule and make a pull, your modification are there without altering the rest of Project B. Obviously, this includes all the hassle offered by version control, that is, conflicts if Project B has worked on utility, probable breaks on other projects if you change the implementation of utility and so on (nothin unusual though).
On the other hand, it is an easy way to pass common code over independent projects.
Let's say I have my shared project here: c:\UnityProjects\DesignPatterns\
and need to include in my Unity project here: c:\UnityProjects\Game\
Solution:
Move all shared code into separate project (c:\UnityProjects\DesignPatterns)
Include this project in solution for all your Unity projects. This allows you to make changes once you need them without reopening shared project separately.
Everything works fine at this moment except Unity editor can't see your external assembly. You have to copy it into any assets folder in Unity. Unity will automatically detect it and create .meta file. Let's create folder for this: c:\UnityProjects\Game\Assets\ExternalDLLs\
We don't want to copy recently built assembly into this directory, we want make it automatically. And Visual Studio post-build event command line is here to help with that. Right click on CSharp project and select properties, then go to Build Events tab and add the following line into post-build event command line:
xcopy $(ProjectDir)..\DesignPatterns\bin\$(ConfigurationName)\DesignPatterns.dll" "$(ProjectDir)\Assets\ExternalDLLs\DesignPatterns.dll" /Y
Now each time we make solution build this command copies our dll from output folder of shared project into our project's asset folder.
Please note: shared project must be built before your unity code assembly is built. It is the case when you always make solution build. In other cases consider copiing assembly from Unity temp directory (you have macros for this folder to select).

Create Visual Studio Project for building using command

I have a solution where there is a dependency on 7zip's sfx. Out of desire to keep the entire solution (plus the sfx) managed and coordinated, I want to create a new project to house all the source files that is used by sfx, and when building, execute a command line that tells 7zip to build a sfx from the source files, and place into the output so that it can be then referenced by actual Visual Studio projects within the same solution.
I think I can figure the command line by using Build events and providing the appropriate macros to ensure that the 7zip's output is placed into the target folder with appropriate name so that it can be then correctly referenced by other VS projects. But what I am not sure about is what Visual Studio project I need to use or steps to take to tell Visual Studio that there isn't going to be any code to be compiled in this project and it just has to execute this script I give it.
The closest thing I can come up with is VS's Make project but I don't know if that is the right thing since this has nothing to do with Make at all.
So, what is the Visual Studio project template I need to use? If empty, then what configuration do I need to perform so that it won't try and look for some code files to compile but instead just execute scripts as part of the solution's build?
For now, it seems that using C++ Makefile Project works. I had to make few configurations:
1) I had to specify the project's "Configuration Type" as "Utility"
2) I used Pre-Build event and provided a command to invoke a batch file included in the project. The batch file then takes care of everything.
3) Normally, non C++ files are not considered for determining whether build is needed or if it's already up to date. To ensure that a new build is perform if the batch file or other key files are edited, I set the file's "File Type" to "MakeFile". Even though it isn't actually a Make file, it ensures that any edits made to the file will cause a new build.
The downsides I've found so far are:
1) C++ uses "Filters", not folders. Therefore, keeping the files in same directory structure is a big PITA. One can "include" files and get a one-to-one mapping between "Filters" and the actual directory structure on disk but it's annoying and tedious. Wish it was a C# project
2) I'm a bit wary about how it will detect new files or other changes for files that I didn't explicitly set to "MakeFile". I expect the source to be stable but I worry that when I realize I need a new file and add it, I might forget and not notice that the build is not correctly including the new file.
I'm not sure if this is the best method but this works for my purpose - having a project to manage external tools as part of bigger build process.

Automation Task in Visual Studios

I am working on a c++ solution which contains 20 projects. My first project builds and I run it as a pre-build event for rest of the projects. Now this executable actually creates some c++ files which should get added to all the other projects which are yet to be compiled. How should I do this? (Using VS2008)
Here are few solutions I thought.
Solution 1:
Let the exe update the vcproj file for all the remaining projects. But in this case as the project is on in VS, it creates some reload popup which I dont want. So is there any way to suppress this popup and just save the changes.
Solution 2:
Visual Automation:
I was just going through some automation API.
The solution and project interface methods would help in adding new file. But will it not create a new pop up as the previous on? Can I use MSbuild here?
You can simply use Generated_*.cpp (or similar pattern) as name of items for corresponding group in project. Than when project is build it will pick up all matching files, even once generated during pre-build steps.
If number of files is small you can just add them to the project directly (which I believe is ok even if they are missing before build).
Note that it may be good idea to generate files into separate folder (like obj\....) so you don't run into cases when someone mistakenly checks in generated files.

Visual Studio 2010 2 projects in 1 solution

I have Console version of app, developed earlier and want to have MFC visualization of it, but with ability to run Console version too. Is it possible to add new project next to existing Console project in the same solution?
Also, I have to link libraries statically.
Yes absolutely it is possible, that is what a Solution file is for. All you have to do is right click in the Solution Explorer and add a new project, the solution file will be created for you.
If you do have multiple projects, you can also specify to start more than one of them when you want to debug, just right click on the solution in Solution Explorer->Properties, Common Properties->Startup Project, then select the Multiple Startup Projects radio button.
Yes, you can have many projects in one solution. Not sure, that you can reference exe file as library for MFC project. For CLI project, yes - you can do that.
Yes you can - add a new project and add files to it. You don't have to link statically, you can link exactly as you want. In fact, you can also copy the old project file edit its contents to rename it and add that to the solution and then remove/add particular files you want.
Its not like C# where you have to mirror the on-disc layout of your project files, C++ files can be referenced where-ever you like.
An alternative would be to add a new build target (eg debug, release, and add 'console - debug' and 'console - release'), then you can mark files as excluded from the builds based on their target, so you can have 1 project that builds 2 slightly different versions of your project.

Visual Studio 2008: How do I include project output as an embedded resource in another project?

I have two projects in one Visual Studio 2008 solution. I'd like to use the primary output from one of the projects as an embedded resource in the other, but for the life of me I can't find any way to accomplish this.
If I simply add the output file as a resource, then it doesn't seem to change when its source project is rebuilt. I even have the project dependencies/build order set up properly and this does not seem to help.
Anyone have any hints for me?
Thanks!
the best option is to "reference" the other project as if it were a class library.
that way you make sure the whole references tree is copied to your output dir.
When you add an existing file to a project, Visual Studio copies the file into the project's directory.
Any subsequent changes to the original file are ignored.
There are two workarounds:
Add a post-build action to the first project that copies its output file to the second project, and edit the dependencies so that the first project is always built first.
Add the output file to the second project as a link (Click the down arrow next to the Add button in the open dialog).
This will reference the file from its original location without making any copies.
Set the output directory of the project that generates the resource to point to the resource directory in the project that uses it.
If that's not possible for some reason, use a post-build command (also available in the project settings) to copy the file there.

Resources