2

I have some batch codes:

Path=C:\Windows\Microsoft.NET\Framework64\v4.0.30319

ECHO Trying TFS build...

msbuild D:\WORK\project\project.sln /p:Config="Debug" /p:Platform="Any CPU" /flp1:logfile=BuildLogProject.txt 

That is working right. And I want to use MSBuild in my C# application.

I added Microsoft.Build.Engine reference and I'm using Engine class. I wrote some codes. But it is not working.

When I build project with Visual Studio or batch program "build succeeded" . When I build the project with my program it finds errors and warnings that are not in the project.

     Engine engine = new Engine();
     engine.BinPath = @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319";
     FileLogger logger = new FileLogger();
     logger.Parameters = @"logfile=D:\WORK\project\BuildLogProject.txt";

     engine.RegisterLogger(logger);
     string projectPath = @"D:\WORK\project\project.sln";

          try
          {
               bool success = engine.BuildProjectFile(projectPath);

          }

          catch (Exception ex)
          {
                System.Windows.Forms.MessageBox.Show(ex.Message);  
          }

          finally
          {
                engine.UnregisterAllLoggers();
                engine.UnloadAllProjects();
          }
2
  • 1
    I guess that you already know that that the BuildEngine.Engine class is marked obsolete as of .NET framework 4 Commented Sep 13, 2012 at 7:20
  • Yes, I'm using Build.BuildEngine. Is it obsolete? However, I know that engine.Binpath method is obsolete. But when I builded my project, there is no error. Commented Sep 13, 2012 at 8:30

1 Answer 1

2

Your problem is that you trying to build .SLN file. Solution file isn't msbuild script itself. only underlying .<XX>proj files are using msbuild format.

Actually when you run msbuild.exe someSLN.sln - msbuild autogenerates script based on your sln file and then execute it by engine. I don't know how you can generate it yourself, but you can peek into autogenerated file by using special environment variable (not working if you trying to pass it as property via command line).

Perform SET MSBuildEmitSolution = 1 and after execution msbuild.exe someSLN.sln you will find someSLN.sln.metaproj file near .sln one. This is what exactly shipped to build engine when you trying to build solution via command line and msbuild.exe

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.