惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
DataBreaches.Net
GbyAI
GbyAI
Microsoft Security Blog
Microsoft Security Blog
博客园_首页
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
月光博客
月光博客
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
腾讯CDC
B
Blog RSS Feed
博客园 - Franky
爱范儿
爱范儿

博客园 - 经霄

Microsoft ProClarity 6.3 releases to manufacturing VSS Object Model Google Service 使用反射动态创建类的实例 - 经霄 - 博客园 AS2005中的维度安全性简介【转】 学位英语通过,特此庆祝一下 VS2005常用插件 AMO编程 - 经霄 - 博客园 Analysis Management Object对象模型 华为前员工:揭密华为“薪酬真相”【转】 VS2005中读写配置文件(一) 微软笔试试题——11月13日,2005年 Structure of the Basic MDX Query(转) 使用ADOMD.NET建立与Analysis Services的连接 IT公司薪水调查 ADOMD.net概述 SQL与MDX语法的比较 AdventureWorks数据库的安装 多维联机数据分析模型和系统设计方法[转]
Windows Services中使用MSBuild实现Build Automation Management
经霄 · 2006-09-19 · via 博客园 - 经霄

Microsoft Build Engine MSBuild)是MicrosoftVisual Studio的新的生成平台。它使得开发人员能够在没有安装Visual Studio 的环境下进行编译。

Windows Service应用程序是一种需要长期运行的应用程序,它没有用户界面,并且也不会产生任何可视化的输出(任何用户消息都会被写入Windows事件日志或者其它自定义的日志中)。因此,它特别适合于服务器环境。在计算机启动时,Windows Service就会自动开始运行(需要设置服务类型为Automatic),它们不需要用户一定登录才行。

Build Automation Management是为了标准化企业的自动化编译过程。通过Windows ServiceMSBuild的结合实现企业的Automation BuildBuild Automation Management可以处理scheduled  Build,也可以处理unscheduled build

创建Windows Service

Windows ServiceAccount设置为User。其它账户可能无权使用Proces

Windows Service中添加Build Code

MSBuild.exe位于%SystemRoot%\Micorsoft .NET\Framework\V2.0.502727目录下。因此,获取该目录所谓的绝对路径。

   string systemRoot = Path.GetDirectoryName(Environment.SystemDirectory);

            string FrameworkPath = systemRoot + @"\Microsoft.NET\Framework";

            if (!Directory.Exists(FrameworkPath))

            {

                throw new DirectoryNotFoundException("The framework directory could not be located.");

            }

            string msBuildDir = FrameworkPath + @"\v2.0.50727";   

获得所需要编译的设置选项。例如,需要编译DebugRelease两个版本。并将这些选项存放在一个临时变量中。    

            string[] configs = new string[] { "Debug", "Release", };    

获得项目路径并调用MSBuild进行编译。

            string projectPath = @"e:\temp\test\test.sln";

            eventLog1.WriteEntry("Start Build");

            foreach (string str in configs)

            {

                Process process = new Process();

                process.StartInfo.FileName = msBuildDir + @"\msbuild.exe";

                process.StartInfo.Arguments = projectPath + @" /p:Configuration=" + str + "\"";

                Console.WriteLine(process.StartInfo.Arguments);

                process.Start();

            }       
完整代码如下:

  string systemRoot = Path.GetDirectoryName(Environment.SystemDirectory);
            
string FrameworkPath = systemRoot + @"\Microsoft.NET\Framework";
            
if (!Directory.Exists(FrameworkPath))
            
{
                
throw new DirectoryNotFoundException("The framework directory could not be located.");
            }

            
string msBuildDir = FrameworkPath + @"\v2.0.50727";         
            
string[] configs = new string[] "Debug""Release};        
            string projectPath = @"e:\temp\test\test.sln";
            eventLog1.WriteEntry(
"Start Build");
            
foreach (string str in configs)
            
{
                Process process 
= new Process();
                process.StartInfo.FileName 
= msBuildDir + @"\msbuild.exe";
                process.StartInfo.Arguments 
= projectPath + @" /p:Configuration=" + str + "\"";
                Console.WriteLine(process.StartInfo.Arguments);
                process.Start();
            }