Skip to content

Commit 99b2a74

Browse files
authored
Fix NuGet lock files and enforce them not changing accidentally (#14611)
## Description This PR fixes NuGet lock files so they're more correct/compliant, and makes it easier to keep them that way. ### Type of Change - Bug fix (non-breaking change which fixes an issue) ### Why We recently updated to WinAppSDK 1.7 and have made other changes to the flavors we build (with different dependencies) so our lock files were out of date / constantly overriding one another. ### What This PR fixes NuGet lock files so they're more correct/compliant. This includes: 1. Updating the `NuGetRestoreForceEvaluateAllSolutions.ps1` script to completely fix the lock files 2. Ensuring every project has a proper `packages.lock.json` file for its default configuration 3. Ensuring projects that are built old AND new arch also have a separate `newarch` lock file 4. Ensuring projects that are build with/without experimental WinUI3 also have a separate `experimentalwinui3` lock file 5. Causing an (optional) CI build error if the lock files change during the build (they shouldn't) with message to re-run the script 6. Removed all unnecessary `packages.config` files which confuse NuGet restoration ## Screenshots N/A ## Testing Verified no complaints about changed lock files after builds in the pipeline. ## Changelog Should this change be included in the release notes: _no_
1 parent 018c214 commit 99b2a74

File tree

78 files changed

+4309
-396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4309
-396
lines changed

.ado/jobs/e2e-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
buildPlatform: ${{ matrix.BuildPlatform }}
8585
buildLogDirectory: $(BuildLogDirectory)
8686
workingDirectory: packages/e2e-test-app
87+
errorOnNuGetLockChanges: false # Sometimes the content hashes of NuGet packages are wrong on VMs, workaround for later .NET versions don't work for UWP C#.
8788

8889
- script: |
8990
echo ##vso[task.setvariable variable=StartedTests]true

.ado/jobs/integration-test.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,15 @@ jobs:
9494
- ${{ if eq(matrix.BuildConfiguration, 'Debug') }}:
9595
# The build is more likely to crash after we've started other bits that
9696
# take up memory. Do the expensive parts of the build first.
97-
- script: yarn windows --no-launch --no-packager --no-deploy --no-autolink --arch ${{ matrix.BuildPlatform }} --logging --buildLogDirectory $(BuildLogDirectory)
98-
displayName: yarn windows --no-launch
99-
workingDirectory: packages/integration-test-app
97+
- template: ../templates/run-windows-with-certificates.yml
98+
parameters:
99+
buildEnvironment: ${{ parameters.BuildEnvironment }}
100+
buildConfiguration: ${{ matrix.BuildConfiguration }}
101+
buildPlatform: ${{ matrix.BuildPlatform }}
102+
buildLogDirectory: $(BuildLogDirectory)
103+
workingDirectory: packages/integration-test-app
104+
moreMSBuildProps: --no-packager --no-deploy --no-autolink
105+
errorOnNuGetLockChanges: false # Sometimes the content hashes of NuGet packages are wrong on VMs, workaround for later .NET versions don't work for UWP C#.
100106

101107
- powershell: Start-Process npm.cmd -ArgumentList "run","start"
102108
displayName: Start packager
@@ -132,8 +138,18 @@ jobs:
132138
workingDirectory: packages/integration-test-app
133139

134140
- ${{ if eq(matrix.BuildConfiguration, 'Release') }}:
135-
- script: yarn windows --release ${{ matrix.DeployOptions }} --no-packager --no-autolink --arch ${{ matrix.BuildPlatform }} --logging --buildLogDirectory $(BuildLogDirectory)
136-
displayName: yarn windows --release
141+
- template: ../templates/run-windows-with-certificates.yml
142+
parameters:
143+
buildEnvironment: ${{ parameters.BuildEnvironment }}
144+
buildConfiguration: ${{ matrix.BuildConfiguration }}
145+
buildPlatform: ${{ matrix.BuildPlatform }}
146+
buildLogDirectory: $(BuildLogDirectory)
147+
workingDirectory: packages/integration-test-app
148+
moreMSBuildProps: ${{ matrix.DeployOptions }} --no-packager --no-autolink
149+
errorOnNuGetLockChanges: false # Sometimes the content hashes of NuGet packages are wrong on VMs, workaround for later .NET versions don't work for UWP C#.
150+
151+
- script: yarn windows --release --no-build ${{ matrix.DeployOptions }} --no-packager --no-autolink --arch ${{ matrix.BuildPlatform }} --logging
152+
displayName: yarn windows --release --no-build
137153
workingDirectory: packages/integration-test-app
138154

139155
- ${{ if ne(matrix.DeployOptions, '--no-deploy') }}:

.ado/jobs/playground.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,6 @@ jobs:
130130
parameters:
131131
workingDir: packages\playground\windows
132132

133-
# NuGet ignores packages.config if it detects <PackageReference>.
134-
# Use restore packages.config directly to keep compabitility with ReactNativePicker.
135-
- pwsh: |
136-
Get-ChildItem -Recurse -Path packages.config |`
137-
Foreach-Object {`
138-
NuGet.exe Restore -PackagesDirectory packages $_`
139-
}
140-
workingDirectory: packages/playground/windows
141-
displayName: Restore packages.config items
142-
143133
- template: ../templates/msbuild-sln.yml
144134
parameters:
145135
solutionDir: packages/playground/windows

.ado/jobs/sample-apps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
deployOption: ${{ matrix.DeployOption }}
8484
buildLogDirectory: ${{ variables['BuildLogDirectory'] }}
8585
workingDirectory: packages/sample-apps
86+
errorOnNuGetLockChanges: false # Sometimes the content hashes of NuGet packages are wrong on VMs, workaround for later .NET versions don't work for UWP C#.
8687

8788
- script: yarn bundle-cpp --verbose
8889
displayName: Create SampleApp bundle
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
parameters:
2+
- name: errorOnNuGetLockChanges
3+
type: boolean
4+
default: true
5+
6+
steps:
7+
- powershell: |
8+
& git add */packages*.lock.json
9+
$changed = git status --porcelain=v1 */packages*.lock.json
10+
if ($changed -ne $null) {
11+
Write-Host "Detected NuGet lock file changes during the build:"
12+
Write-Host Files changed:`n([string]::Join("`n", $changed))
13+
$diff = git diff --cached -- */packages*.lock.json
14+
Write-Host Diff:`n([string]::Join("`n", $diff))
15+
$msg = "Detected NuGet lock file changes during the build. Run vnext/Scripts/NuGetRestoreForceEvaluateAllSolutions.ps1 locally in a VS Dev PowerShell to update lock files, then submit the changes."
16+
if ("${{ parameters.errorOnNuGetLockChanges }}" -eq "True") {
17+
Write-Host "##vso[task.logissue type=error]Detected NuGet lock file changes during the build. Run vnext/Scripts/NuGetRestoreForceEvaluateAllSolutions.ps1 locally in a VS Dev PowerShell to update lock files, then submit the changes."
18+
[Environment]::Exit(-1)
19+
}
20+
}
21+
displayName: Detect NuGet lock file changes during build
22+
condition: succeededOrFailed()

.ado/templates/msbuild-sln.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,7 @@ steps:
5555
$(MsBuildWarnAsErrorArgument)
5656
${{parameters.msbuildArguments}}
5757

58-
- powershell: |
59-
& git add */packages*.lock.json
60-
$changed = git status --porcelain=v1 */packages*.lock.json
61-
if ($changed -ne $null) {
62-
Write-Host "##[warning] Detected packages.lock.json changes. See full log for details."
63-
Write-Host Files changed:`n([string]::Join("`n", $changed))
64-
$diff = git diff --cached -- */packages*.lock.json
65-
Write-Host Diff:`n([string]::Join("`n", $diff))
66-
Write-Host "Run vnext/Scripts/NuGetRestoreForceEvaluateAllSolutions.ps1 to update lock files locally."
67-
}
68-
displayName: Detect packages.lock.json changes during build
69-
condition: succeededOrFailed()
58+
- template: detect-nuget-lockfile-changes.yml
7059

7160
- template: upload-build-logs.yml
7261
parameters:

.ado/templates/run-windows-with-certificates.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ parameters:
2626
- name: restoreForceEvaluate
2727
type: boolean
2828
default: true
29+
- name: errorOnNuGetLockChanges
30+
type: boolean
31+
default : true
2932
- name: moreMSBuildProps
3033
type: string
3134
default: ''
@@ -77,3 +80,8 @@ steps:
7780
workingDirectory: ${{ parameters.workingDirectory }}
7881
7982
- template: ../templates/cleanup-certificate.yml
83+
84+
- ${{ if eq(parameters.restoreLockedMode, 'true') }}:
85+
- template: detect-nuget-lockfile-changes.yml
86+
parameters:
87+
errorOnNuGetLockChanges: ${{ parameters.errorOnNuGetLockChanges }}

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<PropertyGroup Label="NuGet">
2929
<MSBuildProjectExtensionsPath Condition="'$(ProjectName)' != ''">$(RootIntDir)\ProjectExtensions\$(ProjectName)\</MSBuildProjectExtensionsPath>
3030
<MSBuildProjectExtensionsPath Condition="'$(ProjectName)' == ''">$(RootIntDir)\ProjectExtensions\$(MSBuildProjectName)\</MSBuildProjectExtensionsPath>
31+
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
3132
</PropertyGroup>
3233

3334
<!-- User overrides -->
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fix NuGet lock files and enforce them not changing accidentally",
4+
"packageName": "@react-native-windows/automation-channel",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Fix NuGet lock files and enforce them not changing accidentally",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

0 commit comments

Comments
 (0)