none
Deploying MSI using MSBuild properly

    Question

  • Hi there,

    I would like to uninstall and install the new msi that is generated by my project after the build has completed. After it has installed, i would like to start the service automatically. Then i would like to run a series of mstests that exist in my project. I would like this to work on the Build server and local machine.

    How could i go about doing this properly please? If someone could assist me it would be much appreciated. I found out that i have to use the msiexec.exe command.

    in MyProject.csproj  at the moment i have this but i would like help please on how to properly uninstall and install the msi and start the services:

    <Target Name="BeforeBuild">
        <!--grab the test cases and generate the mstests -->
      </Target>
      <Target Name="AfterBuild" DependsOnTargets="BeforeBuild">
        <PropertyGroup>
           <PathToMsi>\\server\folder\msi</PathToMsi>
    	    <LogFile>C:\Temp<LogFile>
         </PropertyGroup>
         <!-- uninstall the exisiting msi -->
    	 Exec Command="msiexec.exe /x "$(PathToMsi)" /qn /l*vx "$(LogFile)"
              IgnoreExitCode="true">
        </Exec>
      </Target>
    
      <Target Name="InstallMsi" AfterTargets="AfterBuild">
          Exec Command="msiexec.exe /i "$(PathToMsi)" /qn /l*vx "$(LogFile)"
              IgnoreExitCode="true">
          <Output TaskParameter="ExitCode" PropertyName="MsiexecExitCode"/>
        </Exec>
    
        <Message Condition="'$(MsiexecExitCode)' == '0'"
                 Text="Successfully installed the '$(PathToMsi)'"/>
    
        <Message Condition="'$(MsiexecExitCode)' != '0'"
                 Text="A problem occurred while installing .msi '$(PathToMsi)'"/>
      </Target>
      
      <Target Name="StartService" AfterTargets="InstallMSi">
        <!-- not sure how to start up the service -->
      </Target>
      
      <Target Name="ExecuteUnitTests" AfterTargets="StartService">
        <Message Text="Running tests..." />
        <PropertyGroup>
          <TestSuccessOrNot>1</TestSuccessOrNot>
        </PropertyGroup>
         <!--Run MSTest exe-->
        <Exec Command='"c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" /testcontainer:..\..\SampleTest\SampleTest\bin\Debug\SampleTest.dll'>
          <Output TaskParameter="ExitCode" PropertyName="TestSuccessOrNot" />
        </Exec>
        <Error Condition="$(TestSuccessOrNot) == 1" Text="Unit tests fail!" />
      </Target>


    Thanks in advance,

    Saturday, January 19, 2013 8:11 PM

Answers

  • Hi,

    I believe your msiexec command in Exec task has extra quotation mark, that caused the problem. Please remove them. Reference to variable like $(TheMsi) directly.

    Exec Command="msiexec.exe /i &quot;$(TheMsi)&quot; /qn /l*vx &quot;$(LogFile)&quot;"

    Also make sure your account has write access to log file path.

    thanks.


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, February 04, 2013 7:39 AM
    Moderator
  • There's a problem: /i & /ju are used exclusively, you can just choose one. 

    /i will install directly

    /ju will advertise, which means it will be installed the first time you use it.

    All other are good.


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, February 04, 2013 11:49 AM
    Moderator

All replies

  • Hi,

    Can the command of install and uninstall msi work?

    Can the msi file be found when the afterbuild called?

    Regards,

    Disley 


    崖山之後無中國,明亡之後無華夏

    Monday, January 21, 2013 9:04 AM
  • Hi,

    I guess that you want to install the windows service after the build progress.

    I think you can view the thread below:

    http://stackoverflow.com/questions/469397/installing-a-win32-service-using-msbuild-and-microsoft-sdc-tasks

    Hope it is helpful to you.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 21, 2013 9:52 AM
    Moderator
  • Hi there,

    Before i can install the msi i decided that it would be better to stop the service that is running. The way i achieved this was I used ServiceController task which is part of the Community.Tasks.

    Now in regards to the code i had posted, i tried to install the msi. I got an error which said that the MSI could not be opened, which exited with error code 1619. I did some further searching and i discovered the following:

            /// <summary>
            /// This installation package could not be opened.
            /// Verify that the package exists and that you can access it,
            /// or contact the application vendor to verify that
            /// this is a valid Windows Installer package.
            /// </summary>
            /// <value>
            /// ERROR_INSTALL_PACKAGE_OPEN_FAILED
            /// </value>
            InstallPackageOpenError = 1619,

    The path to my msi locally on my machine actually specified as such: ..\..\..\Libraries\Prototype\Test.msi

    Does it need to be the full path?

    Also, can anyone confirm whether my syntax is correct in regards to installing the msi please?

    Thanks in advance,

    Monday, January 21, 2013 7:03 PM
  • Hi,

    If we use the full path, can it work?

    From the summary, I guess it can't find the msi or you didn't have access to install it.

    Regards,

    Disley


    崖山之後無中國,明亡之後無華夏

    Wednesday, January 23, 2013 1:08 AM
  • Hi Disley,

    I have tried to install the msi using the full path within the target like so:

       <PropertyGroup>
          <TheMsi>"C:\MyMsi\MyProject.msi"</TheMsi>
          <LogFile>"C:\InstallMsi.log"</LogFile>
        </PropertyGroup>

    Now when i run the build i get the following ui window appearing. Why is this appearing?


    If i click ok it doesnt actually install

    Ideally i would like to install the msi without the user interaction.  Normally if you run the installer it will ask you whether you want to install the software as a local user or by specifying the user account.  How could i get the following code to install the msi without getting the above windows popup?

    For those who would like to know what code i am using to install the msi here it is:

     <Exec Command="msiexec.exe /i &quot;$(TheMsi)&quot; /qn /l*vx &quot;$(LogFile)&quot;" IgnoreExitCode="true">
          <Output TaskParameter="ExitCode" PropertyName="MsiexecExitCode"/>
        </Exec>
    If somebody could assist me with the above issues it would be much appreciated.

    Thanks,



    Monday, January 28, 2013 11:49 AM
  • Hi,

    I tried msiexec.exe command in cmd window. A window like your posted appeared.

    Have you tried the command of InstallUtil to install it?

    More information about InstallUtil please refer to:

    http://msdn.microsoft.com/en-us/library/50614e95.aspx

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 29, 2013 9:36 AM
    Moderator
  • Hi there,

    I tried to use the InstallUtil command through command line and i get the following error:

    Exception occurred while initializing the installation:

    System.IO.FileLoadException: Could not load file or assembly 'file:///C:\MyMsi\MyProject.msi' or one of its dependencies. Data of this type is not supported. (Exception from HRESULT: 0x8007065E).

    This is the command i used:

    installutil /LogFile=myLog.InstallLog C:\MyMsi\MyProject.msi.

    I had a look in the log file and i'm not entirely sure what i should be looking for and I couldn't see anything that strikes out to me.

    Could you advise?

    Thanks in advance,


    • Edited by IndusKing Tuesday, January 29, 2013 11:20 AM
    Tuesday, January 29, 2013 11:20 AM
  • Hi there, i just found out that you cannot use InstallUtil to install an msi file.

    Here is the link:

    Windows Service Installation Error

    Do you have any other suggestions?

    Thanks in advance,

    Tuesday, January 29, 2013 1:56 PM
  • Hi IndusKing,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
     
    Thank you for your understanding and support.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 31, 2013 2:55 AM
    Moderator
  • Hi,

    I believe your msiexec command in Exec task has extra quotation mark, that caused the problem. Please remove them. Reference to variable like $(TheMsi) directly.

    Exec Command="msiexec.exe /i &quot;$(TheMsi)&quot; /qn /l*vx &quot;$(LogFile)&quot;"

    Also make sure your account has write access to log file path.

    thanks.


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, February 04, 2013 7:39 AM
    Moderator
  • Hi there,

    Ah i see. I made sure my account has write access to the log file path. I have taken the extra quotes out so i have something like this:

    Exec Command="msiexec.exe /i /ju $(TheMsi) /qn /l*vx $(LogFile)"

    I still get the Windows Installer window with an "OK" button, I mentioned earlier in the thread.

    Could you tell me please if my command is right?

    Thanks in advance,


    • Edited by IndusKing Monday, February 04, 2013 10:48 AM
    Monday, February 04, 2013 9:40 AM
  • There's a problem: /i & /ju are used exclusively, you can just choose one. 

    /i will install directly

    /ju will advertise, which means it will be installed the first time you use it.

    All other are good.


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, February 04, 2013 11:49 AM
    Moderator
  • Hi there,

    Thanks for clarifying. I believe it is installing now since i am not being prompted with an installer window.

    However, after i installed the msi and try to start the service I get the following message:

    Error: Time out has expired and the operation has not been completed.

    Would you be able to assist me in terms of why i am getting this error?

    Below is the code for starting the service:

    <ServiceController action="Start" servicename="MyServiceName"/>

    The service controller is part of MSBuild.Community.Tasks.Targets.

    Could you assist please?

    Thanks in advance,


    • Edited by IndusKing Tuesday, February 05, 2013 9:57 AM
    Tuesday, February 05, 2013 9:56 AM
  • Hi,

    Nice to know the progress. After you run the build, I suppose you have the service installed.  Have you checked the service? have you tried to start the service manually?  I believe the community msbuild task just do same as manual start.  The key is the service itself.

    thanks.


    Forrest Guo | MSDN Community Support | Feedback to manager

    Tuesday, February 05, 2013 10:18 AM
    Moderator