tags:

views:

549

answers:

4

How can I build a Project programattically in VB.NET ?

+1  A: 

System.Diagnostics.Process.Start("msbuild.exe");

matt_dev
+1  A: 

You can launch devenv.exe, the VS IDE executable, like so:

devenv c:\myproj\myproj.vbproj /rebuild release

It runs silently and you can also specify a log file for output. You might also be able to run vbc, which is the VB compiler.

Chris Tybur
A: 

The following code compiles a application on form load, although would it not be a better idea to have any variables that change stored in a external settings file rather re-compile the application ?

Imports System.Diagnostics.Process
Public Class Form1
    Public Sub BuildProject(ByVal pProject As String)
        Dim lBuildString As String = String.Format("C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe {0} /t:Rebuild /p:Configuation=Release", pProject)
        Dim lReturnID = Shell(lBuildString, AppWinStyle.NormalFocus, False)
        'System.Diagnostics.Process.Start(lBuildString)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        BuildProject("C:\Programming\CommunicationsService\Communications_Service\Service_Tem[\Service_Tem[.vbproj")
    End Sub
End Class
spacemonkeys
A: 

It depends on why you are wanting to do this, but have you considered using TFS or something similar to do this instead of rolling your own process?

Chris Ballance