Build project by code

  • Thread starter Thread starter Tiësto
  • Start date Start date
T

Tiësto

Hi again, here goes the same question once more, but this time shorter and
simpler:

Is there any way to compile a project (a solution file, properly talking)
from another application?
Any object model, class method or any framework component to do this?

thanks in advance.
 
Tiësto,

Pre-.NET 2.0, there really isn't. You could automate an instance of
VS.NET to do this, but that's a rather heavy solution. There is also NAnt,
I believe, which you could use, but you would have to call out to it (create
a new process) in .NET, and there isn't a direct mapping from the project
files in NAnt and C# project files in .NET.

In .NET 2.0, there is MSBUILD, the build engine which VS.NET uses for
building applications. This is accessible from a command line utility as
well as in code through .NET classes. The project files for C# used by
VS.NET 2005 are actually MSBUILD files, with specific logic for C#.

Hope this helps.
 
Nicholas:

I've found this, which is all I need by now...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxlrfbuild.asp

As you mentioned, I create a process, start it, and wait until it finishes.
In the meanwhile I can show some message to the user indicating the process
is taking place. When done, I can query the Process.ExitCode to know if it's
finished ok. I could read the log txt file as well.

I still have to figure out how to analize the possible compilation errors in
order to show the user which problem had place. But I guess I can parse the
result text file.

Additionally, I understand that the application in charge of it needs its
host machine to have VS installed, which in my case, it's no problem so far.

I've also seen that there is a Microsoft.CSharp.Compiler class, but it
processes individual .cs files, which seems bothering for me since I have
the csproj file already created.

Thanks your for replying...
***********************************************

Nicholas Paldino said:
Tiësto,

Pre-.NET 2.0, there really isn't. You could automate an instance of
VS.NET to do this, but that's a rather heavy solution. There is also
NAnt, I believe, which you could use, but you would have to call out to it
(create a new process) in .NET, and there isn't a direct mapping from the
project files in NAnt and C# project files in .NET.

In .NET 2.0, there is MSBUILD, the build engine which VS.NET uses for
building applications. This is accessible from a command line utility as
well as in code through .NET classes. The project files for C# used by
VS.NET 2005 are actually MSBUILD files, with specific logic for C#.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tiësto said:
Hi again, here goes the same question once more, but this time shorter
and simpler:

Is there any way to compile a project (a solution file, properly talking)
from another application?
Any object model, class method or any framework component to do this?

thanks in advance.
 
Back
Top