Created
December 23, 2014 23:33
-
-
Save negue/31cad54f7ec8452fd423 to your computer and use it in GitHub Desktop.
TransformFiles on WinRT 8.1 // Original Code & Guide http://dreamteam-mobile.com/blog/2012/11/windows-store-apps-how-to-keep-both-local-and-store-versions/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<!--Includes all tasks and build modification needed for correct transformation work--> | |
<UsingTask TaskName="TransformXml" | |
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" /> | |
<ItemDefinitionGroup> | |
<!-- Set the default value to false here --> | |
<None> | |
<TransformOnBuild>false</TransformOnBuild> | |
</None> | |
<Content> | |
<TransformOnBuild>false</TransformOnBuild> | |
</Content> | |
<Resource> | |
<TransformOnBuild>false</TransformOnBuild> | |
</Resource> | |
<EmbeddedResource> | |
<TransformOnBuild>false</TransformOnBuild> | |
</EmbeddedResource> | |
<AppxManifest> | |
<TransformOnBuild>false</TransformOnBuild> | |
</AppxManifest> | |
<_FilesToTransform> | |
<IsAppConfig>false</IsAppConfig> | |
</_FilesToTransform> | |
</ItemDefinitionGroup> | |
<PropertyGroup> | |
<TransformAllFilesDependsOn> | |
DiscoverFilesToTransform; | |
</TransformAllFilesDependsOn> | |
</PropertyGroup> | |
<Target Name="DiscoverFilesToTransform"> | |
<Message Text="====================== Running 1. DiscoverFilesToTransform" /> | |
<!-- | |
This will look through items list: None & Content for those | |
with Metadata <TransformOnBuild>True</TransformOnBuild> | |
--> | |
<ItemGroup> | |
<_FilesToTransform Include="@(None);@(Content);@(Resource);@(EmbeddedResource);@(AppxManifest)" | |
Condition=" '%(TransformOnBuild)' == 'true' " /> | |
</ItemGroup> | |
<PropertyGroup> | |
<_AppConfigFullPath>@(AppConfigWithTargetPath->'%(RootDir)%(Directory)%(Filename)%(Extension)')</_AppConfigFullPath> | |
</PropertyGroup> | |
<!-- Now look to see if any of these are the app.config file --> | |
<ItemGroup> | |
<_FilesToTransform Condition=" '%(FullPath)'=='$(_AppConfigFullPath)' "> | |
<IsAppConfig>true</IsAppConfig> | |
</_FilesToTransform> | |
</ItemGroup> | |
<ItemGroup> | |
<_FilesToTransformNotAppConfig Include="@(_FilesToTransform)" | |
Condition=" '%(IsAppConfig)'!='true'" /> | |
<_AppConfigToTransform Include="@(_FilesToTransform)" | |
Condition=" '%(IsAppConfig)'=='true'" /> | |
</ItemGroup> | |
<Message Text="FilesToTransform= @(_FilesToTransform)" /> | |
</Target> | |
<Target Name="TransformAllFiles" DependsOnTargets="$(TransformAllFilesDependsOn)" BeforeTargets="_ValidatePresenceOfAppxManifestItems"> | |
<!-- Now we have the item list _FilesToTransformNotAppConfig and _AppConfigToTransform item lists --> | |
<Message Text="====================== Running 2. TransformAllFiles" /> | |
<!-- Transform the app.config file --> | |
<ItemGroup> | |
<_AppConfigTarget Include="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" /> | |
</ItemGroup> | |
<PropertyGroup> | |
<_AppConfigDest>@(_AppConfigTarget->'%(FullPath)')</_AppConfigDest> | |
</PropertyGroup> | |
<Message Text="_AppConfigTarget = @(_AppConfigTarget) _AppConfigToTransform = @(_AppConfigToTransform) _FilesToTransformNotAppConfig = @(_FilesToTransformNotAppConfig)" /> | |
<MakeDir Directories="@(_FilesToTransformNotAppConfig->'$(OutDir)%(RelativeDir)')" | |
Condition="Exists('%(RelativeDir)%(Filename).$(Configuration)%(Extension)')" /> | |
<TransformXml Source="@(_AppConfigToTransform->'%(FullPath)')" | |
Transform="%(RelativeDir)%(Filename).$(Configuration)%(Extension)" | |
Destination="$(_AppConfigDest)" | |
Condition=" Exists('%(RelativeDir)%(Filename).$(Configuration)%(Extension)') " /> | |
<TransformXml Source="@(_FilesToTransformNotAppConfig->'%(FullPath)')" | |
Transform="%(RelativeDir)%(Filename).$(Configuration)%(Extension)" | |
Destination="@(_FilesToTransformNotAppConfig->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)')" | |
Condition=" Exists('%(RelativeDir)%(Filename).$(Configuration)%(Extension)') " /> | |
<Copy SourceFiles="$(OutDir)Package.appxmanifest" DestinationFiles="$(OutDir)modified.appxmanifest_" | |
SkipUnchangedFiles="true" ContinueOnError="True" /> | |
</Target> | |
<!-- Finds out if there is a custom AppxManifest override item, --> | |
<!-- validates that one and only one manifest exists, --> | |
<!-- extracts identity name and version out of the manifest, --> | |
<!-- defines ProjectPriIndexName, --> | |
<!-- and defines SourceAppxManifest item. --> | |
<Target Name="_ValidatePresenceOfAppxManifestItems" | |
DependsOnTargets="$(ValidatePresenceOfAppxManifestItemsDependsOn)"> | |
<Message Text="====================== Running 3. _ValidatePresenceOfAppxManifestItems" /> | |
<ItemGroup> | |
<CustomAppxManifest Include="@(Content)" Condition="'%(Identity)' == 'AppxManifest.xml'" /> | |
</ItemGroup> | |
<ValidateAppxManifestItems AppxPackageProject="$(AppxPackage)" | |
AppxManifestItems="$(OutDir)modified.appxmanifest_" | |
CustomAppxManifestItems="@(CustomAppxManifest)"> | |
<Output TaskParameter="IdentityName" PropertyName="AppxManifestIdentityName" /> | |
<Output TaskParameter="IdentityVersion" PropertyName="AppxManifestIdentityVersion" /> | |
</ValidateAppxManifestItems> | |
<Message Text="IDENTITY NAME TAKEN FROM $(OutDir)modified.appxmanifest_ IS $(AppxManifestIdentityName)" /> | |
<ItemGroup> | |
<SourceAppxManifest Include="$(OutDir)modified.appxmanifest_" Condition="'@(AppxManifest)' != ''" /> | |
<SourceAppxManifest Include="@(CustomAppxManifest)" Condition="'@(CustomAppxManifest)' != ''" /> | |
</ItemGroup> | |
<PropertyGroup Condition="'$(ProjectPriIndexName)' == ''"> | |
<ProjectPriIndexName Condition="'$(AppxPackage)' == 'true'">$(AppxManifestIdentityName)</ProjectPriIndexName> | |
<ProjectPriIndexName Condition="'$(AppxPackage)' != 'true'">$(AppxPriInitialPath)</ProjectPriIndexName> | |
</PropertyGroup> | |
<PropertyGroup> | |
<_CustomAppxManifestUsed Condition="'@(CustomAppxManifest)' == ''">false</_CustomAppxManifestUsed> | |
<_CustomAppxManifestUsed Condition="'@(CustomAppxManifest)' != ''">true</_CustomAppxManifestUsed> | |
</PropertyGroup> | |
</Target> | |
<PropertyGroup> | |
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | |
</PropertyGroup> | |
<PropertyGroup> | |
<AppxMSBuildToolsPath Condition="'$(AppxMSBuildToolsPath)' == ''">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\AppxPackage\</AppxMSBuildToolsPath> | |
<AppxMSBuildTaskAssembly Condition="'$(AppxMSBuildTaskAssembly)' == ''">$(AppxMSBuildToolsPath)Microsoft.Build.AppxPackage.dll</AppxMSBuildTaskAssembly> | |
</PropertyGroup> | |
<UsingTask AssemblyFile="$(AppxMSBuildTaskAssembly)" TaskName="Microsoft.Build.AppxPackage.GenerateAppxManifest" /> | |
<Target Name="_GenerateCurrentProjectAppxManifest" | |
Condition="Exists(@(AppxManifest))" | |
Inputs="$(MSBuildAllProjects);@(_GenerateCurrentProjectAppxManifestInput)" | |
Outputs="$(FinalAppxManifestName)"> | |
<Message Text="====================== Running _GenerateCurrentProjectAppxManifest" /> | |
<ItemGroup> | |
<AppxManifestMetadata Include="$(MakePriExeFullPath)" /> | |
</ItemGroup> | |
<GenerateAppxManifest AppxManifestInput="$(OutDir)modified.appxmanifest_" | |
AppxManifestOutput="$(FinalAppxManifestName)" | |
ApplicationExecutableName="$(TargetName)" | |
FrameworkSdkReferences="@(FrameworkSdkReference)" | |
NonFrameworkSdkReferences="@(NonFrameworkSdkReference)" | |
CertificateThumbprint="$(PackageCertificateThumbprint)" | |
CertificateFile="$(PackageCertificateKeyFile)" | |
DefaultResourceLanguage="$(DefaultResourceLanguage)" | |
QualifiersPath="$(_QualifiersPath)" | |
PackageArchitecture="$(PackageArchitecture)" | |
SDKWinmdFiles="@(_AppxSDKWinmdFilesForHarvest)" | |
WinmdFiles="@(_AppxWinmdFilesToHarvest)" | |
ManagedWinmdInprocImplementation="$(ManagedWinmdInprocImplementation)" | |
OSMinVersion="$(AppxOSMinVersion)" | |
OSMaxVersionTested="$(AppxOSMaxVersionTested)" | |
OSMinVersionReplaceManifestVersion="$(AppxOSMinVersionReplaceManifestVersion)" | |
OSMaxVersionTestedReplaceManifestVersion="$(AppxOSMaxVersionTestedReplaceManifestVersion)" | |
PackageSigningEnabled="$(AppxPackageSigningEnabled)" | |
EnableSigningChecks="$(EnableSigningChecks)" | |
ManifestMetadata="@(AppxManifestMetadata)" | |
TargetPlatformIdentifier="$(TargetPlatformIdentifier)" /> | |
<Message Importance="low" Text="@(AppxManifest) -> $(FinalAppxManifestName)" /> | |
<Message Text="TESTING OVERRIDE" /> | |
<Message Text="Transformed APPX File: $(OutDir)modified.appxmanifest_" /> | |
</Target> | |
<!-- Validates final Appx manifest. --> | |
<Target Name="_ValidateAppxManifest" | |
Condition="'$(AppxValidateAppxManifest)' == 'true'"> | |
<Message Text="====================== Running _ValidateAppxManifest" /> | |
<PropertyGroup> | |
<TransformedStoreAssociationFile Condition=" !Exists(@(StoreAssociationFile->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)'))">@(StoreAssociationFile)</TransformedStoreAssociationFile> | |
<TransformedStoreAssociationFile Condition=" Exists(@(StoreAssociationFile->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)'))">@(StoreAssociationFile->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)')</TransformedStoreAssociationFile> | |
</PropertyGroup> | |
<ValidateAppxManifest Input="@(FinalAppxManifest)" | |
SourceAppxManifest="$(OutDir)modified.appxmanifest_" | |
AppxManifestSchema="@(AppxManifestSchema)" | |
StoreAssociationFile="$(TransformedStoreAssociationFile)" | |
TargetPlatformVersion="$(TargetPlatformVersion)" | |
TargetPlatformIdentifier="$(TargetPlatformIdentifier)" | |
OSMinVersion="$(AppxOSMinVersion)" | |
OSMaxVersionTested="$(AppxOSMaxVersionTested)" | |
PlatformVersionDescriptions="@(PlatformVersionDescription)" | |
ResolvedSDKReferences="@(RecursiveResolvedSDKReference)" | |
ValidateWinmds="$(_CustomAppxManifestUsed)" | |
StrictManifestValidationEnabled="$(AppxStrictManifestValidationEnabled)" | |
WinmdFiles="@(_AppxWinmdFilesToHarvest)" | |
SDKWinmdFiles="@(_AppxSDKWinmdFilesForHarvest)" | |
NonFrameworkSdkReferences="@(NonFrameworkSdkReference)" | |
ManagedWinmdInprocImplementation="$(ManagedWinmdInprocImplementation)" | |
ValidateManifest="$(AppxValidateAppxManifest)"> | |
<Output TaskParameter="Resources" ItemName="_ManifestResources" /> | |
</ValidateAppxManifest> | |
<!--<ValidateAppxManifest Input="@(FinalAppxManifest)" | |
SourceAppxManifest="@(SourceAppxManifest)" | |
AppxManifestSchema="$(AppxManifestSchema)" | |
StoreAssociationFile="$(TransformedStoreAssociationFile)" | |
OSMinVersion="$(AppxOSMinVersion)" | |
OSMaxVersionTested="$(AppxOSMaxVersionTested)" | |
ValidateWinmds="$(_CustomAppxManifestUsed)" | |
StrictManifestValidationEnabled="$(AppxStrictManifestValidationEnabled)" | |
WinmdFiles="@(_AppxWinmdFilesToHarvest)" | |
SDKWinmdFiles="@(_AppxSDKWinmdFilesForHarvest)" | |
NonFrameworkSdkReferences="@(NonFrameworkSdkReference)" | |
ManagedWinmdInprocImplementation="$(ManagedWinmdInprocImplementation)" | |
/>--> | |
</Target> | |
<!-- Executes pre-upload validation of the appx package. --> | |
<Target Name="_ValidateAppxPackage" | |
Condition="'$(AppxPackageValidationEnabled)' == 'true'"> | |
<Message Text="====================== Running _ValidateAppxPackage" /> | |
<PropertyGroup> | |
<TransformedStoreAssociationFile Condition=" !Exists(@(StoreAssociationFile->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)'))">@(StoreAssociationFile)</TransformedStoreAssociationFile> | |
<TransformedStoreAssociationFile Condition=" Exists(@(StoreAssociationFile->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)'))">@(StoreAssociationFile->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)')</TransformedStoreAssociationFile> | |
</PropertyGroup> | |
<Message Text="Store Association Transformed" /> | |
<Message Text="Using File: $(TransformedStoreAssociationFile)" /> | |
<ValidateAppxPackage | |
SourceAppxManifest="$(OutDir)modified.appxmanifest_" | |
AppxManifest="@(FinalAppxManifest)" | |
StoreAssociationFile="$(TransformedStoreAssociationFile)" | |
PackageArchitecture="$(PackageArchitecture)" | |
AppxPackagePayload="@(AppxPackagePayload)" | |
QueryNamespacePrefix="$(AppxManifestQueryNamespacePrefix)" | |
ManifestImageFileNameQueries="@(AppxManifestImageFileNameQuery)" | |
ResolvedSDKReferences="@(RecursiveResolvedSDKReference)" | |
AllowDebugFrameworkReferencesInManifest="$(AppxPackageAllowDebugFrameworkReferencesInManifest)" /> | |
</Target> | |
<Target Name="_GenerateAppxPackageRecipeFile" | |
Inputs="$(MSBuildAllProjects);@(_GenerateAppxPackageRecipeInput)" | |
Outputs="$(AppxPackageRecipe)"> | |
<Message Text="====================== Running _GenerateAppxPackageRecipeFile" /> | |
<GenerateAppxPackageRecipe | |
AppxManifestXml="%(FinalAppxManifest.FullPath)" | |
SourceAppxManifest="$(OutDir)Package.appxmanifest" | |
SolutionConfiguration="$(Configuration)|$(Platform)" | |
PayloadFiles="@(AppxPackagePayload)" | |
FrameworkSdkPackages="@(FrameworkSdkPackage)" | |
RecipeFile="$(AppxPackageRecipe)" | |
SystemBinaries="@(AppxSystemBinary)" | |
ReservedFileNames="@(AppxReservedFileName)" | |
AppxManifestSchemas="@(AppxManifestSchema)" | |
ManifestFileNameQueries="@(AppxManifestFileNameQuery)" | |
ManifestImageFileNameQueries="@(AppxManifestImageFileNameQuery)" | |
PackageArchitecture="$(PackageArchitecture)" | |
ProjectDir="$(ProjectDir)" | |
IntermediateOutputPath="$(IntermediateOutputPath)" | |
MakePriExtensionPath="$(InProcessMakePriExtensionPath)" | |
TargetPlatformIdentifier="$(TargetPlatformIdentifier)" | |
IndexedPayloadFiles="@(IndexedPayloadFiles)" | |
UseResourceIndexerApi="$(AppxUseResourceIndexerApi)" /> | |
<Message Importance="low" Text="Manifest: %(FinalAppxManifest.Identity)" /> | |
<Message Importance="low" Text="Payload: %(AppxPackagePayload.TargetPath) from %(AppxPackagePayload.FullPath)" /> | |
<Message Importance="low" Text="SDK reference: %(RecursiveResolvedSDKReference.TargetPath) from %(RecursiveResolvedSDKReference.FullPath)" /> | |
<Message Importance="low" Text="$(MSBuildProjectName) -> $(AppxPackageRecipe)" /> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment