.NET Framework Bookmark and Share   
 index > MSBuild > MSBuild : Building .proj files from C# code without calling msbuild from command line
 

MSBuild : Building .proj files from C# code without calling msbuild from command line

Hi folks,

I think everybody can assume what is going on in my head so I will be short now : I want to build .proj file representing solution or single project BUT NOT TO USE Process.Start("...") with "msbuild" from command line if possible using Microsoft.Build.* assemblies (or in some other way if possible) within C# code.Is this acheivable or I have to find some other way?

Thank you very much!

Best regards,
Civa
Civa
Hi Civa,

You can useMicrosoft.Build.BuildEngine namespace in C# code, Microsoft.Build.BuildEngine namespace represents the MSBuild engine, and Engine Class represents the MSBuild engine, you can use Engine Class to call MSBuild to build project file, please refer the following code:

            Engine engine = new Engine();
           // Initialize code
            bool success = engine.BuildProjectFile(@"c:\temp\validate.proj");

For more information, please see:

http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.aspx

If I misunderstood you, or you have any questions, please let me know.

Best Regards,
Nancy
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Nancy Shao
Thank you very much Nancy for your answer!

Im afraid I already did so but I keep getting on error something like : "There are no targets in projects" and later on something like : "Product version can not be determined" or similar.I would be very grateful if You can provide me the skeleton of that .proj file or some basic content of it so I could use it along with managed classes to build projects and/or solution in some situations.

I think it is about .proj file itself ,I'm certainly missing something in it.I did 'set MSBuildEmitSolution=1' as custom task for building solution file and that didn't give much results so I tried to build projects in solution one by one dealing with .proj file.

I'm relatively new in MSBuild so I'm certainly missing some core points.

Thank you once again!

Regards,

Civa


Civa
Hi Civa,

I would suggest you refer to the .csproj file in your machine, they are very similar. Forthe main skeleton of .proj, please refer to :

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TestTarget1;TestTarget2" ToolsVersion="3.5">

  <ItemGroup>
    <PathDir Include="C:\RootDir\UniqueDir1"/>
    <PathDir Include="C:\RootDir\UniqueDir2" />
  </ItemGroup>

  <Target Name="TestTarget1" Outputs="%(PathDir.Identity)">
    <PropertyGroup>
      <RootPath>%(PathDir.Identity)</RootPath>
    </PropertyGroup>

    <ItemGroup>
      <SubDirectory Include="Common1"/>
      <SubDirectory Include="Common2"/>
    </ItemGroup>

    <CreateItem Include="@(SubDirectory->'$(RootPath)\%(Identity)')">
      <Output TaskParameter="Include" ItemName="FullPath"/>
    </CreateItem>
  
    <Message Text="@(FullPath)"/>
  </Target>

</Project>

For more information, you can refer to this link in MSDN:


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Nancy Shao
Thank you very much Nancy for useful info I will try with this file.

Best regards,

Civa
Civa

You can use google to search for other answers

Custom Search

More Threads

• Framework 2.0 and 3.5 how to work together
• Build Acition-Visual Stuido
• How can I know if it's a release or debug build?
• Automated build process - error MSB4018: The "GenerateResource" task failed unexpectedly
• Web project deployment options
• Setup project contents changes after close and reopen of the solution
• Sdc.Tasks SetEnvironmentVariable - Why wont it set environment variables for me?
• First non-beta FreeToDev MSbuild Tasks Suite release available now.
• How to get the directory name from an item
• Meaning of DebugXX flags