MSBuild target to create the .appx package?


  • Does anyone have an example of using MSBuild to create the Windows 8 package (.appx)?  What target is used to create the package?

    I have a solution with multiple configurations and currently I have to manually switch between each and manually create the packages.  It would be great if I could use MSBuild and PowerShell to automate this.

    I wasn't sure if I should post this to the MSBuild forum (http://social.msdn.microsoft.com/Forums/en-US/msbuild/threads) - but I thought posting it here made more sense.

    Thursday, June 7, 2012 11:08 PM

All replies

  • If you're using msbuild on the command line, just invoking a build on the project will also build an app package by default. If you're using the VS IDE, you can select multiple packages to be built in the Create App Package wizard and the build process will automatically loop through all the configurations and build an app package for each.

    Friday, June 8, 2012 1:05 AM
  • Hi Candy,

    Thank you - I know where the .NET Framework is installed and where to find msbuild.  But I'm a but confused on which msbuild I should use when invoking a build for winRT applications.  

    Can you let me know the full path the msbuild I should use?  Can you provide a sample msbuild call from the command line that would build and create a package for any sample from http://code.msdn.microsoft.com/windowsapps

    For example, what would be the msbuild command line invocation for the C# of the "XAML essential controls sample" http://code.msdn.microsoft.com/windowsapps/Basic-Controls-29318599 ?

    Friday, June 8, 2012 11:45 PM
  • bump.


    Monday, June 11, 2012 5:39 PM
  • In addition to the .NET Framework, you will also need to install VS (VS Express for Win8 at the minimum) in order to build metro apps on the command line. You can use the Visual Studio command prompt for building and it will automatically pick up the correct version of msbuild.exe for you. Here are the steps you need to take in order to build "XAML essential controls sample":

    1. Install VS
    2. Open the BasicControls project, right-click on the project and go to Store --> Create App Package to create a package for local (You need to do this step before you can build the project on the command line the first time because there is no existing .pfx file in the project and you'll need that to build on the command line since building on the command line also does create a package.)
    3. Launch the VS command prompt
    4. On the command prompt, type "msbuild <location of the BasicControls.csproj> /p:Platform="Any CPU"

    Note on step 2. You should not have to do this on newly created projects because the .pfx file is now created on project creation.

    Monday, June 11, 2012 6:42 PM
  • That works, thanks.
    When you mentioned the vs command prompt, I realized I could also use in a standard command prompt -

      C:\Program Files\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat
      (for Windows 8 32 bits, with VS 2012 RC Professional installed)

    It also works for winRT solutions and you can set the configuration, which will set the platform, etc.... -

      msbuild MYSOLUTION.sln /t:Rebuild /p:Configuration=MYCONFIGURATION


    Monday, June 11, 2012 7:01 PM
  • What if I'm creating packages for OEM distribution, and not using the store?

    In your steps, in step 2, you right-click on the project and go to Store --> Create App Package.  But in my case, I work with multiple vendors and my app will is currently not in the store - I just need to create the packages.

    Store > Create App Package...
    Do you eant to build a package to upload to the Windows Store? > No > Next
    Specify Package settings > Create

    I end up with a folder in "AppPackages", for example AppPackages\MYPROJECT_1.0.3.2_AnyCPU_MYCONFIGURATION_Test

    When running msbuild the way you described, this package is not created.

    How can I use msbuild to produce this package?

    Monday, June 11, 2012 7:14 PM
  • The package gets created on project build by using the msbuild command I provided earlier. Are you sure you're not doing an incremental build which means you made no updates to the project so the build didn't rebuild and hence the package isn't being created? Try deleting the packages under "AppPackages" and try again.

    Monday, June 11, 2012 7:22 PM
  • If I delete the packages under "AppPackages" and try again, it works.

    But if I make changes to the project (.xaml or .cs changes) and run the msbuild command without deleting the existing packages in "AppPackages", then it doesn't work - a new package is not created.

    How can I force the creation of a package?

    Thursday, October 18, 2012 6:16 PM