Skip to content

Commit c815b8a

Browse files
authored
feat(windows): allow specifying MSBuild properties (#2497)
1 parent ae07378 commit c815b8a

12 files changed

+107
-42
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ jobs:
564564
yarn build:windows
565565
- name: Generate Visual Studio solution
566566
run: |
567-
yarn install-windows-test-app --use-nuget
567+
yarn install-windows-test-app --use-nuget --msbuildprops WindowsTargetPlatformVersion=10.0.26100.0
568568
working-directory: example
569569
- name: Test `react-native config`
570570
run: |
@@ -616,7 +616,7 @@ jobs:
616616
yarn build:windows
617617
- name: Generate Visual Studio solution
618618
run: |
619-
yarn install-windows-test-app --use-nuget
619+
yarn install-windows-test-app --use-nuget --msbuildprops WindowsTargetPlatformVersion=10.0.26100.0
620620
working-directory: template-example
621621
- name: Determine whether the Windows app needs to be built
622622
id: affected

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"init": "scripts/init.mjs",
6060
"init-test-app": "scripts/init.mjs",
6161
"configure-test-app": "scripts/configure.mjs",
62-
"install-windows-test-app": "windows/test-app.mjs"
62+
"install-windows-test-app": "windows/app.mjs"
6363
},
6464
"repository": {
6565
"type": "git",

scripts/types.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,36 @@ type InferredOptionTypes<O> = { [key in keyof O]: InferredOptionType<O[key]> };
177177

178178
export type Args<O> = InferredOptionTypes<O> & { _: string[] };
179179

180+
/************************
181+
* windows/app.mjs *
182+
************************/
183+
184+
type Resources = string[] | { windows?: string[] };
185+
186+
export type AssetItems = {
187+
assetItems: string[];
188+
assetItemFilters: string[];
189+
assetFilters: string[];
190+
};
191+
192+
export type Assets = {
193+
assetItems: string;
194+
assetItemFilters: string;
195+
assetFilters: string;
196+
};
197+
198+
export type AppManifest = {
199+
name?: string;
200+
singleApp?: string;
201+
resources?: Resources;
202+
windows?: {
203+
appxManifest?: string;
204+
certificateKeyFile?: string;
205+
certificatePassword?: string;
206+
certificateThumbprint?: string;
207+
};
208+
};
209+
180210
/***********************
181211
* windows/project.mjs *
182212
***********************/
@@ -193,6 +223,7 @@ export type AppxBundle = {
193223

194224
export type MSBuildProjectOptions = {
195225
autolink: boolean;
226+
msbuildprops?: string;
196227
useFabric?: boolean;
197228
useHermes?: boolean;
198229
useNuGet: boolean;
@@ -218,36 +249,6 @@ export type MSBuildProjectConfigurator = (
218249
info: ProjectInfo
219250
) => MSBuildProjectParams;
220251

221-
/************************
222-
* windows/test-app.mjs *
223-
************************/
224-
225-
type Resources = string[] | { windows?: string[] };
226-
227-
export type AssetItems = {
228-
assetItems: string[];
229-
assetItemFilters: string[];
230-
assetFilters: string[];
231-
};
232-
233-
export type Assets = {
234-
assetItems: string;
235-
assetItemFilters: string;
236-
assetFilters: string;
237-
};
238-
239-
export type AppManifest = {
240-
name?: string;
241-
singleApp?: string;
242-
resources?: Resources;
243-
windows?: {
244-
appxManifest?: string;
245-
certificateKeyFile?: string;
246-
certificatePassword?: string;
247-
certificateThumbprint?: string;
248-
};
249-
};
250-
251252
/**************
252253
* schema.mjs *
253254
**************/

test/pack.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ describe("npm pack", () => {
322322
"windows/Win32/pch.h",
323323
"windows/Win32/resource.h",
324324
"windows/Win32/targetver.h",
325+
"windows/app.mjs",
325326
"windows/project.mjs",
326-
"windows/test-app.mjs",
327327
"windows/uwp.mjs",
328328
"windows/win32.mjs",
329329
]);

test/windows/copyAndReplace.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { equal, fail, match, rejects } from "node:assert/strict";
22
import { afterEach, describe, it } from "node:test";
33
import { readTextFile as readTextFileActual } from "../../scripts/helpers.js";
4-
import { copyAndReplace as copyAndReplaceActual } from "../../windows/test-app.mjs";
4+
import { copyAndReplace as copyAndReplaceActual } from "../../windows/app.mjs";
55
import { fs, setMockFiles } from "../fs.mock.ts";
66

77
describe("copyAndReplace()", () => {

test/windows/findUserProjects.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { deepEqual, equal } from "node:assert/strict";
22
import * as os from "node:os";
33
import * as path from "node:path";
44
import { describe, it } from "node:test";
5-
import { findUserProjects, toProjectEntry } from "../../windows/test-app.mjs";
5+
import { findUserProjects, toProjectEntry } from "../../windows/app.mjs";
66

77
describe("findUserProjects()", () => {
88
it("finds all user projects, ignoring android/ios/macos/node_modules", () => {

test/windows/generateSolution.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { equal } from "node:assert/strict";
22
import * as path from "node:path";
33
import { afterEach, beforeEach, describe, it } from "node:test";
4-
import { generateSolution as generateSolutionActual } from "../../windows/test-app.mjs";
4+
import { generateSolution as generateSolutionActual } from "../../windows/app.mjs";
55
import { fs, setMockFiles } from "../fs.mock.ts";
66

77
describe("generateSolution()", () => {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { equal, ok, throws } from "node:assert/strict";
2+
import { describe, it } from "node:test";
3+
import { parseMSBuildProperties } from "../../windows/app.mjs";
4+
5+
describe("parseMSBuildProperties()", () => {
6+
it("handles empty string", () => {
7+
ok(!parseMSBuildProperties(undefined), "should return undefined");
8+
ok(!parseMSBuildProperties(""), "should return undefined");
9+
});
10+
11+
it("parses single property", () => {
12+
equal(parseMSBuildProperties("Prop=Value"), "<Prop>Value</Prop>");
13+
});
14+
15+
it("parses multiple properties", () => {
16+
equal(
17+
parseMSBuildProperties("Prop1=Value1,Prop2=Value2"),
18+
"<Prop1>Value1</Prop1>\n<Prop2>Value2</Prop2>"
19+
);
20+
});
21+
22+
it("throws on invalid input", () => {
23+
throws(() => parseMSBuildProperties("NULL"));
24+
throws(() => parseMSBuildProperties("Prop="));
25+
throws(() => parseMSBuildProperties("=Value"));
26+
throws(() => parseMSBuildProperties("Prop=Value,"));
27+
});
28+
});

test/windows/replaceContent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { equal } from "node:assert/strict";
22
import { describe, it } from "node:test";
3-
import { replaceContent } from "../../windows/test-app.mjs";
3+
import { replaceContent } from "../../windows/app.mjs";
44

55
describe("replaceContent()", () => {
66
it("returns same string with no replacements", () => {

windows/ExperimentalFeatures.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
-->
3434
<UseExperimentalNuget>false</UseExperimentalNuget>
3535

36+
<!-- AdditionalMSBuildProperties -->
37+
3638
<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
3739
</PropertyGroup>
3840
</Project>

0 commit comments

Comments
 (0)