Skip to content
Open
43 changes: 43 additions & 0 deletions lib/modules/manager/nuget/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,49 @@ describe('modules/manager/nuget/artifacts', () => {
]);
});

it('properly appends additional commands options when requested', async () => {
const execSnapshots = mockExecAll();
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
git.getFiles.mockResolvedValueOnce({
'packages.lock.json': 'Current packages.lock.json',
});
fs.getLocalFiles.mockResolvedValueOnce({
'packages.lock.json': 'New packages.lock.json',
});
expect(
await nuget.updateArtifacts({
packageFileName: 'project.csproj',
updatedDeps: [{ depName: 'dep' }],
newPackageFileContent: '{}',
config: {
...config,
postUpdateOptions: ['dotnetEnableWindowsTargeting'],
},
}),
).toEqual([
{
file: {
contents: 'New packages.lock.json',
path: 'packages.lock.json',
type: 'addition',
},
},
]);
expect(execSnapshots).toMatchObject([
{
cmd: 'dotnet restore project.csproj --force-evaluate --configfile /tmp/renovate/cache/__renovate-private-cache/nuget/nuget.config -p:EnableWindowsTargeting=true',
options: {
cwd: '/tmp/github/some/repo',
env: {
NUGET_PACKAGES:
'/tmp/renovate/cache/__renovate-private-cache/nuget/packages',
MSBUILDDISABLENODEREUSE: '1',
},
},
},
]);
});

it('runs workload restore and updates lock file', async () => {
const execSnapshots = mockExecAll();
fs.getSiblingFileName.mockReturnValueOnce('packages.lock.json');
Expand Down
7 changes: 6 additions & 1 deletion lib/modules/manager/nuget/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ async function runDotnetRestore(
toolConstraints: [{ toolName: 'dotnet', constraint: dotnetVersion }],
};

const dotnetRestoreOpts = [''];
if (config.postUpdateOptions?.includes('dotnetEnableWindowsTargeting')) {
dotnetRestoreOpts.push('-p:EnableWindowsTargeting=true');
}

const cmds = [
...dependentPackageFileNames.map(
(fileName) =>
`dotnet restore ${quote(
fileName,
)} --force-evaluate --configfile ${quote(nugetConfigFile)}`,
)} --force-evaluate --configfile ${quote(nugetConfigFile)}${dotnetRestoreOpts.join(' ')}`,
),
];

Expand Down
13 changes: 13 additions & 0 deletions lib/modules/manager/nuget/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ You can enable this behavior by adding `dotnetWorkloadRestore` to the `postUpdat
"postUpdateOptions": ["dotnetWorkloadRestore"]
}
```

### Windows targeting

In case you need to allow Windows targeting during package restore, e.g. adding the `-p:EnableWindowsTargeting=true` CLI argument to the
Sometimes package restore needs Windows targeting enabled.
Normally, you do this by adding `-p:EnableWindowsTargeting=true` to the `dotnet restore` command.
In Renovate, the same effect is achieved by adding `dotnetEnableWindowsTargeting` to `postUpdateOptions`.

```json
{
"postUpdateOptions": ["dotnetEnableWindowsTargeting"]
}
```
1 change: 1 addition & 0 deletions lib/modules/manager/nuget/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface Registry {
readonly name?: string;
sourceMappedPackagePatterns?: string[];
}

export interface ProjectFile {
readonly isLeaf: boolean;
readonly name: string;
Expand Down