Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

Auto build a project upon execution

Is there a way to tell Visual Studio to build a project (one project of many within a solution) whenever I run the project?
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

  • The F6 key builds a solution.  
  • Whenever you execute a solution the out of date projects are automatically rebuilt.
>>whenever I run the project?  What do you mean by run a project if the above statements are of no use?
Avatar of HLRosenberger

ASKER

I meant run the solution.   I have a class library project within the solution that is not added as a reference.   But I would like to build this project every time I run the solution.
Whenever you execute a solution the out of date projects are automatically rebuilt.
So - you don't need to do anything.
The automatic build is not happening.  Or does not appear to be.  When you say "rebuilt" does that mean the DLL, PDB and XML files are created?
All files required to compile dll and exe files are checked for their last time of change and compared to the dll/exe.  Any newer source files will result in the dll/exe being recompiled/rebuilt.
If nothing is being rebuilt then either everything is at the newest version or you have some sort of problem on your system.  For the second you can select the 'clean' sub menu point on the 'build' menu which should delete any dll/exe files the project/solution creates forcing them to be rebuilt from the source files
regarding your comments:

I have a class library project within the solution that is not added as a reference.   But I would like to build this project every time I run the solution.

To be able to show the starting project faster, only the required components are built and only if needed. If your project is not referenced by the starting project (or any dependencies) then it just not built. In that case your only solution is to manually build the solution yourself (CTRL-SHIFT-B).
Eric - Yes, that my scenario.  I was hoping there was a way to force a build upon execution, anyway.
is your other project you want to compile a .exe or a .dll?
DLL.
I don't think you can do much (other than full rebuild). It would have been a .exe, you could have started the other project at the same time as your main one.
I thought I read something a long time ago that you can create a "build list" that executes a series of commands??
if you open the properties of your project and go to the "Build events" tab, you will see that you add some commands but I wouldn't go that way.

Can I ask why you need to compile a DLL that is not referenced?
The simplest way to do what you want is to actually use this dll in a 'dummy' function - one that isn't actually ever used - so it will be rebuilt when your main exe is rebuilt.  


Note it means the dll will need to be distributed with the exe.  However the only sensible reason I can think of for you having this dll in the solution implies you have a suite of apps/dlls that you will want all built at once for distribution.
Eric - yes.  The code I've inherited does a very clever thing.   It has some 10 or so of it's own DLLs that it uses, but none are added as references in the main project.   Instead, each is loaded dynamically at runtime.  To make a long story short, this application supports what it calls "Plugins" - the ability for user to add new functionality to the application, with touching the source code.   In order to debug things, I need the DLL/PDB rebuilt each time I run, otherwise the source code does not match the DLL/PDB.
the easy answer: press CTRL-SHIFT-B before F5
or use the pre/post build events to call msbuild to build your projects
I know how to build it manually.  That's what I'm trying to get around.  pre/post build events?  Tell me more!
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>It has some 10 or so of it's own DLLs that it uses, but none are added as references in the main project.   Instead, each is loaded dynamically at runtime.

If all dll's are installed at the end user PC is there a reason you don't want to just add reference/dummy function to call each in your main app.  Then a build will rebuild them if they are out of date.  My understanding is that the .net environment won't actually compile any of that code from the intermediate into real code until it is called at runtime.
this sounds promising.  I give it a shot...