Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 109
  • Last Modified:

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?
0
HLRosenberger
Asked:
HLRosenberger
  • 8
  • 7
  • 5
1 Solution
 
AndyAinscowCommented:
  • 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?
0
 
HLRosenbergerAuthor Commented:
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.
0
 
AndyAinscowCommented:
Whenever you execute a solution the out of date projects are automatically rebuilt.
So - you don't need to do anything.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
HLRosenbergerAuthor Commented:
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?
0
 
AndyAinscowCommented:
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
0
 
Éric MoreauSenior .Net ConsultantCommented:
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).
0
 
HLRosenbergerAuthor Commented:
Eric - Yes, that my scenario.  I was hoping there was a way to force a build upon execution, anyway.
0
 
Éric MoreauSenior .Net ConsultantCommented:
is your other project you want to compile a .exe or a .dll?
0
 
HLRosenbergerAuthor Commented:
DLL.
0
 
Éric MoreauSenior .Net ConsultantCommented:
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.
0
 
HLRosenbergerAuthor Commented:
I thought I read something a long time ago that you can create a "build list" that executes a series of commands??
0
 
Éric MoreauSenior .Net ConsultantCommented:
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?
0
 
AndyAinscowCommented:
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.
0
 
HLRosenbergerAuthor Commented:
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.
0
 
Éric MoreauSenior .Net ConsultantCommented:
the easy answer: press CTRL-SHIFT-B before F5
0
 
Éric MoreauSenior .Net ConsultantCommented:
or use the pre/post build events to call msbuild to build your projects
0
 
HLRosenbergerAuthor Commented:
I know how to build it manually.  That's what I'm trying to get around.  pre/post build events?  Tell me more!
0
 
Éric MoreauSenior .Net ConsultantCommented:
create a batch file that compile your project and add the call to this batch file in the pre-build events of your starting project : https://msdn.microsoft.com/en-us/library/42x5kfw4.aspx
0
 
AndyAinscowCommented:
>>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.
0
 
HLRosenbergerAuthor Commented:
this sounds promising.  I give it a shot...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now