I have an app with background tasks that I want registered or not based on a build time variable. I know that in a .csproj file I can use Condition in the to specify the manifest to use. The problem with this is that most of the contents of the two manifests are identical. Can I either (a) somehow use a condition in a single manifest instead, or (b) factor out the common elements and somehow include them into two otherwise minimal manifests? I didn't find a way to do either, resulting in duplication which is obviously bad.
Asked
Active
Viewed 528 times
2
-
I'm confused about why you have two manifests? And what is the Condition you mentioned to specify the manifest to use? Can you show more details about the Condition or code snippet? – Faywang - MSFT Jan 23 '20 at 06:16
-
Well to declare a background task you have to put it in the appxmanifest as
... I need that declaration to be conditional on a define constant. Right now we have two manifests and the build server uses one or the other based on a constant; this is quite awful because it duplicates all the other stuff in the manifests. – Display Name Jan 24 '20 at 21:53 -
Do you mean that you want to control when background tasks are registered via controlling the declarations in the manifest? If it is, you need to control the registration of background tasks with code instead of through declarations in the manifest. – Faywang - MSFT Jan 27 '20 at 08:59
-
I thought it's not possible to register it's not declared in the manifest with
– Display Name Jan 28 '20 at 05:57 -
Yes, if you don't declare the background task in the app manifest, you can't run background tasks successfully, so you need to declare it in the manifest. But about when to register background tasks, it should be controlled by when you use BackgroundTaskBuilder.Register() method after you declare in the manifest. – Faywang - MSFT Jan 28 '20 at 08:05
-
Well my goal is to have builds conditionally include or exclude the assemblies for the background task classes and not even build them based on build configuration setting such as an environment variable. But how do I avoid duplication of the manifest if I can't use a conditional in the manifest or have two manifests that include the common stuff? – Display Name Jan 28 '20 at 21:29
-
We have never seen the practice of two manifests, and we cannot guarantee whether this approach is reasonable. – Faywang - MSFT Jan 29 '20 at 07:55
-
2@Faywang-MSFT: Well, take a look at Windows Terminal, then: https://github.com/microsoft/terminal/blob/fc7b052461cd7c513b3a057a10ae88d9e83dfbc8/src/cascadia/CascadiaPackage/CascadiaPackage.wapproj#L38-L48 – SamB Jan 02 '21 at 00:08
-
@SamB if you add this as an answer, I will accept it – Display Name Jan 22 '21 at 03:49
1 Answers
0
We do this with two appxmanifest files as seen in Windows Terminal.
<AppxManifest Include="Package.appxmanifest" Condition="'$(Configuration)'!='Debug'" SubType="Designer"/>
<AppxManifest Include="Package-DEBUG.appxmanifest" Condition="'$(Configuration)'=='Debug'" SubType="Designer"/>

James Esh
- 2,219
- 1
- 24
- 41