.NET工程的自动化编译

Author:zfive5(zhaozidong)

Email :zfive5@yahoo.com.cn

星期六去了一趟海龙,内存终于升G了,下午回来看了一会儿.NETmsdn帮助,发现

DTE,觉得对大团队自动化编译很有利用价值了,就想写点东西出来!

通过这个接口很容易实现VC7的工程编译自动化,什么也不说了, 一切尽在代码中!

MSDN中描述DTE结构的示意图如下:

<shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 413.25pt; HEIGHT: 483.75pt" type="#_x0000_t75"><imagedata src="http://blog.csdn.net/images/blog_csdn_net/zfive5/74723/r_netauto.jpg" o:title="AutoMS"></imagedata></shape>



VC7.1的代码如下:

#pragma warning( disable : 4278 )

//The following #import imports DTE based on its LIBID

#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("7.0") lcid("0") raw_interfaces_only named_guids

#pragma warning( default : 4278 )

using namespace EnvDTE; // optional

//……

void Ct3Dlg::OnBnClickedOk()

{

CoInitialize(NULL);

{

_variant_t varRelease=L"Release";

_bstr_t bstrSlnPath=L"C://test//W3//W3.sln";

try

{

CComPtr<EnvDTE::_DTE> pZFIVE5_DTE;

_Solution *pZFIVE5_S=NULL;

SolutionBuild *pZFIVE5_SB=NULL;

SolutionConfigurations *pZFIVE5_SCs=NULL;

SolutionConfiguration *pZFIVE5_SC=NULL;

pZFIVE5_DTE.CoCreateInstance(L"VisualStudio.DTE.7.1", 0);

pZFIVE5_DTE->get_Solution(&pZFIVE5_S);

if(pZFIVE5_S==NULL)

{

pZFIVE5_DTE->Quit();

goto ZFive5ComRet;

}

pZFIVE5_S->Open(bstrSlnPath);

VARIANT_BOOL var;

pZFIVE5_S->get_IsOpen(&var);

if (var==VARIANT_TRUE)

{

pZFIVE5_S->get_SolutionBuild(&pZFIVE5_SB);

if(pZFIVE5_SB==NULL)

{

pZFIVE5_S->Release();

pZFIVE5_S=NULL;

pZFIVE5_DTE->Quit();

goto ZFive5ComRet;

}

pZFIVE5_SB->get_SolutionConfigurations(&pZFIVE5_SCs);

if(pZFIVE5_SCs==NULL)

{

pZFIVE5_SB->Release();

pZFIVE5_SB=NULL;

pZFIVE5_S->Release();

pZFIVE5_S=NULL;

pZFIVE5_DTE->Quit();

goto ZFive5ComRet;

}

pZFIVE5_SCs->Item(varRelease,&pZFIVE5_SC);

if(pZFIVE5_SC!=NULL)

{

pZFIVE5_SC->Activate();

pZFIVE5_SC->Release();

pZFIVE5_SC=NULL;

}

pZFIVE5_SCs->Release();

pZFIVE5_SCs=NULL;

pZFIVE5_SB->Build(VARIANT_TRUE);

pZFIVE5_SB->Release();

pZFIVE5_SB=NULL;

pZFIVE5_S->Close(0);

}

else

{

AfxMessageBox("打开工程错误!");

}

pZFIVE5_S->Release();

pZFIVE5_S=NULL;

pZFIVE5_DTE->Quit();

}

catch(...)

{

AfxMessageBox("接口调用错误!");

}

}

ZFive5ComRet:

::CoUninitialize();

return;

}

写到这里不能不佩服ms的深谋远虑!!!

除非感到安全,否则人们就不能去迎接变化。

----《最后期限》

的确是一句名言!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值