1

When people download my project from GitHub, I launch a Setup Guide on Start Up that contains a button that reads 'Launch Connection String Builder'.

The problem is GitHub doesn't store the .exe, so I have to explain in every video or tutorial 'Open Connection String Builder Solution > Build' then either run Connection String Builder or click the button 'Launch Connection String Builder Button'.

If there is a way I can compile on demand the Connection String Builder project this would be my ideal solution.

I know I could move the form in the Connection String Builder project to inside of the main (DataTier.Net) project, but I don't want to do that if I don't have to since I keep a shortcut on my desktop to Connection String Builder.

The folder of ConnectionStringBuilder is in a tools folder which is a sub folder of the main project.

I was looking for a Rosylyn method to compile a project on demand, but couldn't find anything by Googling this (I did give up after a couple of pages I admit). As illustrated by the code sample below, I know how to check if the .exe exists, and I would like to be able to something like RosylnCompiler.Compile(pathToProject); if the .exe does not exist.

string temp = "../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Debug/ConnectionBuilder.exe";
string path = Path.GetFullPath(temp);
if (File.Exists(path))
{
    string databaseName = ...;
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(path, databaseName);
    System.Diagnostics.Process.Start(startInfo);
}
else
{
    MessageBox.Show("Sorry we could not find DataTier.Net Connection String Builder.", "App Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

Is there anyway to do this? If not I can update my message boxes to be instructions or copy the form into my main project if I have to, but a compile on demand would be my ideal solution.

Ryan Prechel
  • 6,592
  • 5
  • 23
  • 21
  • You can use the MSBuild.exe application for that if I understood you correctly. – Luchspeter Jul 17 '19 at 15:46
  • https://learn.microsoft.com/de-de/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019 You can call this exe via C# and that way automatically build the exe. – Luchspeter Jul 17 '19 at 15:47
  • Many thanks. I knew I read something about this. –  Jul 17 '19 at 15:48
  • I am posting the English language version of your link to help people who do not speak (dutch maybe?). https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild?view=vs-2019 –  Jul 17 '19 at 15:51
  • Wups yes sorry. I have it configured to show the content in english so I did not notice. Thank you. German btw ;) – Luchspeter Jul 17 '19 at 15:56

1 Answers1

0

Assuming there are no errors, Visual Studio will ensure all projects in the current build configuration are built when 1) the Build Solution command is executed or 2) the current build configuration is started (e.g., when either the Start Debugging or Start Without Debugging command is executed). In addition, assuming there are no errors, Visual Studio will build all projects in the current build configuration when the Rebuild Solution command is executed.

Thus, you should be able to ensure that the project for the Connection String Builder application is built by including it in all of the build configurations defined for the solution.

See Understand build configurations for more information regarding build configurations.

In addition, unless you only have a Debug configuration, you should not assume that the Debug version of the Connection String Builder application was built (i.e., ../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Debug/ConnectionBuilder.exe from your question). If your solution only defines the default Debug and Release build configurations, you can determine the correct path as follows:

#if DEBUG
../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Debug/ConnectionBuilder.exe
#else
../../../Tools/ConnectionStringBuilder/ConnectionBuilder/bin/Release/ConnectionBuilder.exe
#endif
Ryan Prechel
  • 6,592
  • 5
  • 23
  • 21
  • I know I could add the other project, I have just done it this way for so long it is hard for me to change. On Code Plex, it was just a zip file so this was never an issue, I just never got around to fixing it until now. MS Build will work for what I need, but thanks for the suggestion. –  Jul 17 '19 at 17:26
  • I do not understand what would be hard to change. Assuming you have a project file for the application, all you would need to change is the solution file. – Ryan Prechel Jul 17 '19 at 18:08
  • If the project is open source on GitHub, I would be happy to make a patch with the change if you want. – Ryan Prechel Jul 17 '19 at 18:10
  • I came here to tell you my attempt at msbuild failed, so I went with your way. The one weird thing I noticed, that if (from a clone) I rebuild the solution, it builds the Connection String Builder project with everything else, but if I just start the program (Debug > Start), the program does not compile the Connection Builder form. Since you volunteered, if you want to see if you can improve this: https://github.com/DataJuggler/DataTier.Net (DataTier.Net is an Entity Framework alternative that uses all stored procedures and is easier to use). Thanks –  Jul 17 '19 at 18:40
  • I had to uninstall and add back all my NuGet packages when I moved the project to the Solution, but thats ok. I just checked in a new version with NuGet packages updated. –  Jul 17 '19 at 18:58
  • I got everything working now. I had to uncheck an option in Configuration Manager: Tools > Options > Projects and Solutions > Build and Run > Uncheck the box for Only build start up projects and depencies on run. Once I unchecked that, everything works. I just saved 15 seconds out of every video no one watches (since YouTube knows I watched an Alex Jones video, once. Ok Twice). –  Jul 17 '19 at 19:27