Skip to content

Commit 727792a

Browse files
feat(manager/nuget): extract msbuild sdk from Import (#35206)
1 parent 4cb2bb2 commit 727792a

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/modules/manager/nuget/extract.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,46 @@ describe('modules/manager/nuget/extract', () => {
138138
expect(res).toBeNull();
139139
});
140140

141+
it('extracts msbuild sdk from the Import element', async () => {
142+
const packageFile = 'sample.csproj';
143+
const sample = `
144+
<Project>
145+
<PropertyGroup>
146+
<TargetFramework>net7.0</TargetFramework> <!-- this is a dummy value -->
147+
<NuspecFile>$(MSBuildThisFileDirectory)\tdlib.native.nuspec</NuspecFile>
148+
<NuspecProperties>version=$(PackageVersion)</NuspecProperties>
149+
</PropertyGroup>
150+
<Import Project="Sdk.props" Sdk="My.Custom.Sdk" Version="1.2.3" />
151+
</Project>
152+
`;
153+
const res = await extractPackageFile(sample, packageFile, config);
154+
expect(res?.deps).toEqual([
155+
{
156+
depName: 'My.Custom.Sdk',
157+
depType: 'msbuild-sdk',
158+
currentValue: '1.2.3',
159+
datasource: 'nuget',
160+
},
161+
]);
162+
expect(res?.deps).toHaveLength(1);
163+
});
164+
165+
it('does not extract msbuild sdk from the Import element if version is missing', async () => {
166+
const packageFile = 'sample.csproj';
167+
const sample = `
168+
<Project>
169+
<PropertyGroup>
170+
<TargetFramework>net7.0</TargetFramework> <!-- this is a dummy value -->
171+
<NuspecFile>$(MSBuildThisFileDirectory)\tdlib.native.nuspec</NuspecFile>
172+
<NuspecProperties>version=$(PackageVersion)</NuspecProperties>
173+
</PropertyGroup>
174+
<Import Project="Sdk.props" Sdk="My.Custom.Sdk" />
175+
</Project>
176+
`;
177+
const res = await extractPackageFile(sample, packageFile, config);
178+
expect(res).toBeNull();
179+
});
180+
141181
it('extracts dependency with lower-case Version attribute', async () => {
142182
const contents = codeBlock`
143183
<Project Sdk="Microsoft.NET.Sdk">

lib/modules/manager/nuget/extract.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ function extractDepsFromXml(xmlNode: XmlDocument): NugetPackageDependency[] {
118118
datasource: NugetDatasource.id,
119119
});
120120
}
121+
} else if (name === 'Import') {
122+
const depName = attr?.Sdk;
123+
const version = attr?.Version;
124+
if (depName && version) {
125+
results.push({
126+
depName,
127+
currentValue: version,
128+
depType: 'msbuild-sdk',
129+
datasource: NugetDatasource.id,
130+
});
131+
}
121132
} else {
122133
if (name === 'Project') {
123134
if (attr?.Sdk) {

0 commit comments

Comments
 (0)