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

推荐订阅源

C
Cisco Blogs
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
Jina AI
Jina AI
Project Zero
Project Zero
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
Simon Willison's Weblog
Simon Willison's Weblog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tenable Blog
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
Last Week in AI
Last Week in AI
月光博客
月光博客
雷峰网
雷峰网
G
Google Developers Blog
V
V2EX
T
Tor Project blog
罗磊的独立博客
Schneier on Security
Schneier on Security
Know Your Adversary
Know Your Adversary
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Privacy International News Feed
S
Securelist
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
小众软件
小众软件
Scott Helme
Scott Helme
I
Intezer
T
Threat Research - Cisco Blogs
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
C
CERT Recently Published Vulnerability Notes
Security Archives - TechRepublic
Security Archives - TechRepublic
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
L
Lohrmann on Cybersecurity
T
Troy Hunt's Blog
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Latest news
Latest news
AWS News Blog
AWS News Blog
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 经霄

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();
            }