Skip to content

Commit

Permalink
fix(manager/nuget): validate msbuild sdks (#11750)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Sep 15, 2021
1 parent 196df0d commit d05137f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 32 deletions.
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "5.0.302",
"rollForward": "latestMajor"
}
}
54 changes: 35 additions & 19 deletions lib/manager/nuget/extract.spec.ts
Expand Up @@ -117,25 +117,41 @@ describe('manager/nuget/extract', () => {
it('extracts msbuild-sdks from global.json', async () => {
const packageFile = 'msbuild-sdk-files/global.json';
const contents = loadFixture(packageFile);
expect(await extractPackageFile(contents, packageFile, config))
.toMatchInlineSnapshot(`
Object {
"deps": Array [
Object {
"currentValue": "5.0.302",
"depName": "dotnet-sdk",
"depType": "dotnet-sdk",
"skipReason": "unsupported-datasource",
},
Object {
"currentValue": "0.2.0",
"datasource": "nuget",
"depName": "YoloDev.Sdk",
"depType": "msbuild-sdk",
},
],
}
`);
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchObject({
deps: [
{
currentValue: '5.0.302',
depName: 'dotnet-sdk',
depType: 'dotnet-sdk',
skipReason: 'unsupported-datasource',
},
{
currentValue: '0.2.0',
datasource: 'nuget',
depName: 'YoloDev.Sdk',
depType: 'msbuild-sdk',
},
],
});
});

it('extracts dotnet-sdk from global.json', async () => {
const packageFile = 'msbuild-sdk-files/global.1.json';
const contents = loadFixture(packageFile);
expect(
await extractPackageFile(contents, 'global.json', config)
).toMatchObject({
deps: [
{
currentValue: '5.0.302',
depName: 'dotnet-sdk',
depType: 'dotnet-sdk',
skipReason: 'unsupported-datasource',
},
],
});
});

it('handles malformed global.json', async () => {
Expand Down
20 changes: 11 additions & 9 deletions lib/manager/nuget/extract/global-manifest.ts
Expand Up @@ -35,16 +35,18 @@ export function extractMsbuildGlobalManifest(
});
}

for (const depName of Object.keys(manifest['msbuild-sdks'])) {
const currentValue = manifest['msbuild-sdks'][depName];
const dep: PackageDependency = {
depType: 'msbuild-sdk',
depName,
currentValue,
datasource: datasourceNuget.id,
};
if (manifest['msbuild-sdks']) {
for (const depName of Object.keys(manifest['msbuild-sdks'])) {
const currentValue = manifest['msbuild-sdks'][depName];
const dep: PackageDependency = {
depType: 'msbuild-sdk',
depName,
currentValue,
datasource: datasourceNuget.id,
};

deps.push(dep);
deps.push(dep);
}
}

return { deps };
Expand Down
6 changes: 4 additions & 2 deletions lib/manager/nuget/readme.md
@@ -1,3 +1,5 @@
The `nuget` configuration object is used to control settings for the NuGet package manager.
The NuGet package manager supports a SDK-style `.csproj`/`.fsproj`/`.vbproj` format, as described [here](https://natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/).
This means that .NET Core projects are all supported but any .NET Framework projects need to be updated to the new `.csproj`/`.fsproj`/`.vbproj` format in order to be detected and supported by Renovate.
The NuGet package manager supports a SDK-style `.csproj`/`.fsproj`/`.vbproj`/`.props`/`.targets` format, as described [here](https://natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/).
This means that .NET Core projects are all supported but any .NET Framework projects need to be updated to the new `.csproj`/`.fsproj`/`.vbproj`/`.props`/`.targets` format in order to be detected and supported by Renovate.

The NuGet manager also supports `global.json` and `.config/dotnet-tools.json` SDK files.
4 changes: 2 additions & 2 deletions lib/manager/nuget/types.ts
Expand Up @@ -16,8 +16,8 @@ export interface Registry {
}

export interface MsbuildGlobalManifest {
readonly sdk: MsbuildSdk;
readonly 'msbuild-sdks': Record<string, string>;
readonly sdk?: MsbuildSdk;
readonly 'msbuild-sdks'?: Record<string, string>;
}

export interface MsbuildSdk {
Expand Down

0 comments on commit d05137f

Please sign in to comment.