.NET工程的自动化编译

Author:zfive5(zhaozidong)

Email :[email protected]

 

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

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

 

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

 

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

 

 

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的深谋远虑!!!

 

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

----《最后期限》

 

的确是一句名言!!!

 

你可能感兴趣的:(c,.net,null,email,envdte)