以编程方式设置Visual Studio 2010属性

时间:2012-09-29 10:41:47

标签: c# visual-studio-2010

我正在创建一个构建代码的应用程序。但是我想以编程方式设置Visual Studio 2010属性。

例如,我想设置INCLUDE目录,参考目录,库目录这个将从VS GUI设置的所有目录,但我想以编程方式进行此操作。

1 个答案:

答案 0 :(得分:1)

你可以看到这样做的msdn文章:http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.engine.buildprojectfile(v = vs.90).aspx

    using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.BuildEngine;

namespace BuildAProjectCS
{
    class Program
    {       
        static void Main(string[] args)
        {
            // Instantiate a new Engine object
            Engine engine = new Engine();

            // Point to the path that contains the .NET Framework 2.0 CLR and tools
            engine.BinPath = @"c:\windows\microsoft.net\framework\v2.0.xxxxx";


            // Instantiate a new FileLogger to generate build log
            FileLogger logger = new FileLogger();

            // Set the logfile parameter to indicate the log destination
            logger.Parameters = @"logfile=C:\temp\build.log";

            // Register the logger with the engine
            engine.RegisterLogger(logger);

            // Build a project file 
            bool success = engine.BuildProjectFile(@"c:\temp\validate.proj");

            //Unregister all loggers to close the log file
            engine.UnregisterAllLoggers();

            if (success)
                Console.WriteLine("Build succeeded.");
            else
                Console.WriteLine(@"Build failed. View C:\temp\build.log for details");

        }
    }
}