|
1 | 1 | import {
|
2 | 2 | extractTargetFrameworksFromFiles,
|
| 3 | + extractProjectSdkFromProjectFile, |
3 | 4 | isSupportedByV2GraphGeneration,
|
| 5 | + isSupportedByV3GraphGeneration, |
4 | 6 | } from '../../lib';
|
5 | 7 |
|
6 | 8 | describe('Target framework tests', () => {
|
@@ -273,10 +275,178 @@ describe('Target framework tests', () => {
|
273 | 275 | targetFramework: 'net48',
|
274 | 276 | expected: false,
|
275 | 277 | },
|
| 278 | + // .NET Framework < 5 with dot |
| 279 | + { |
| 280 | + targetFramework: 'net4.8', |
| 281 | + expected: false, |
| 282 | + }, |
276 | 283 | ])(
|
277 | 284 | 'accepts or rejects specific target frameworks for runtime assembly parsing when targetFramework is: $targetFramework.original',
|
278 | 285 | ({ targetFramework, expected }) => {
|
279 | 286 | expect(isSupportedByV2GraphGeneration(targetFramework)).toEqual(expected);
|
280 | 287 | },
|
281 | 288 | );
|
282 | 289 | });
|
| 290 | + |
| 291 | +describe('SDK project type tests', () => { |
| 292 | + it.each([ |
| 293 | + { |
| 294 | + description: 'Project Sdk attribute - Web', |
| 295 | + manifest: ` |
| 296 | + <Project Sdk="Microsoft.NET.Sdk.Web"> |
| 297 | + </Project> |
| 298 | + `, |
| 299 | + expectedProjectSdk: 'Microsoft.NET.Sdk.Web', |
| 300 | + }, |
| 301 | + { |
| 302 | + description: 'Project Sdk attribute - MSBuild', |
| 303 | + manifest: ` |
| 304 | + <Project Sdk="MSBuild.Sdk.Extras/2.0.54"> |
| 305 | + </Project> |
| 306 | + `, |
| 307 | + expectedProjectSdk: 'MSBuild.Sdk.Extras/2.0.54', |
| 308 | + }, |
| 309 | + { |
| 310 | + description: 'Top level Sdk element - MSTest', |
| 311 | + manifest: ` |
| 312 | + <Project> |
| 313 | + <Sdk Name="MSTest.Sdk/3.8.3" /> |
| 314 | + </Project> |
| 315 | + `, |
| 316 | + expectedProjectSdk: 'MSTest.Sdk/3.8.3', |
| 317 | + }, |
| 318 | + { |
| 319 | + description: |
| 320 | + 'Additive Sdk elements (project attribute takes precedence) - Aspire', |
| 321 | + manifest: ` |
| 322 | + <Project Sdk="Microsoft.NET.Sdk"> |
| 323 | + <Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" /> |
| 324 | + <ItemGroup> |
| 325 | + <PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0"/> |
| 326 | + </ItemGroup> |
| 327 | + </Project> |
| 328 | + `, |
| 329 | + expectedProjectSdk: 'Microsoft.NET.Sdk', |
| 330 | + }, |
| 331 | + { |
| 332 | + description: 'Custom csproj not using and SDK', |
| 333 | + manifest: ` |
| 334 | + <?xml version="1.0" encoding="utf-8"?> |
| 335 | + <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 336 | + <Import Project="$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')" /> |
| 337 | + <PropertyGroup> |
| 338 | + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
| 339 | + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
| 340 | + <ProjectGuid>{A1B2C3D4-E5F6-7890-1234-567890ABCDEF}</ProjectGuid> |
| 341 | + <OutputType>Exe</OutputType> |
| 342 | + <AppDesignerFolder>Properties</AppDesignerFolder> |
| 343 | + <RootNamespace>MyLegacyNetFxApp</RootNamespace> |
| 344 | + <AssemblyName>MyLegacyNetFxApp</AssemblyName> |
| 345 | + <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> |
| 346 | + <FileAlignment>512</FileAlignment> |
| 347 | + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
| 348 | + <Deterministic>true</Deterministic> |
| 349 | + </PropertyGroup> |
| 350 | + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
| 351 | + <PlatformTarget>AnyCPU</PlatformTarget> |
| 352 | + <DebugSymbols>true</DebugSymbols> |
| 353 | + <DebugType>full</DebugType> |
| 354 | + <Optimize>false</Optimize> |
| 355 | + <OutputPath>bin\\Debug\\</OutputPath> |
| 356 | + <DefineConstants>DEBUG;TRACE</DefineConstants> |
| 357 | + <ErrorReport>prompt</ErrorReport> |
| 358 | + <WarningLevel>4</WarningLevel> |
| 359 | + </PropertyGroup> |
| 360 | + <Import Project="$(MSBuildToolsPath)\\Microsoft.CSharp.targets" /> |
| 361 | + </Project> |
| 362 | + `, |
| 363 | + expectedProjectSdk: undefined, |
| 364 | + }, |
| 365 | + { |
| 366 | + description: 'Unsupported SDK - Godot', |
| 367 | + manifest: ` |
| 368 | + <Project Sdk="Godot.NET.Sdk/4.3.0"> |
| 369 | + </Project> |
| 370 | + `, |
| 371 | + expectedProjectSdk: 'Godot.NET.Sdk/4.3.0', |
| 372 | + }, |
| 373 | + { |
| 374 | + description: 'Unsupported SDK - Uno', |
| 375 | + manifest: ` |
| 376 | + <Project Sdk="Uno.Sdk/6.0.96"> |
| 377 | + </Project> |
| 378 | + `, |
| 379 | + expectedProjectSdk: 'Uno.Sdk/6.0.96', |
| 380 | + }, |
| 381 | + ])( |
| 382 | + '.Net .csproj is SDK-style project: $description', |
| 383 | + async ({ manifest, expectedProjectSdk }) => { |
| 384 | + const projectSdk = await extractProjectSdkFromProjectFile(manifest); |
| 385 | + expect(projectSdk).toEqual(expectedProjectSdk); |
| 386 | + }, |
| 387 | + ); |
| 388 | + |
| 389 | + it.each([ |
| 390 | + // No target framework, no way to restore the project. |
| 391 | + { |
| 392 | + targetFramework: '', |
| 393 | + projectSdk: 'Microsoft.NET.Sdk', |
| 394 | + expected: false, |
| 395 | + }, |
| 396 | + // .NET Core with NET SDK. |
| 397 | + { |
| 398 | + targetFramework: 'netcoreapp3.1', |
| 399 | + projectSdk: 'Microsoft.NET.Sdk', |
| 400 | + expected: true, |
| 401 | + }, |
| 402 | + // .NET Standard. |
| 403 | + { |
| 404 | + targetFramework: 'netstandard1.5', |
| 405 | + projectSdk: 'Microsoft.NET.Sdk', |
| 406 | + expected: true, |
| 407 | + }, |
| 408 | + // .NET >= 5 |
| 409 | + { |
| 410 | + targetFramework: 'net7.0', |
| 411 | + projectSdk: 'Microsoft.NET.Sdk', |
| 412 | + expected: true, |
| 413 | + }, |
| 414 | + // .NET Framework 3.5 |
| 415 | + { |
| 416 | + targetFramework: 'net35', |
| 417 | + projectSdk: 'Microsoft.NET.Sdk', |
| 418 | + expected: true, |
| 419 | + }, |
| 420 | + // .NET Framework 4 |
| 421 | + { |
| 422 | + targetFramework: 'net481', |
| 423 | + projectSdk: 'Microsoft.NET.Sdk', |
| 424 | + expected: true, |
| 425 | + }, |
| 426 | + // Uno SDK with any supported .NET framework. |
| 427 | + { |
| 428 | + targetFramework: 'net9.0', |
| 429 | + projectSdk: 'Uno.Sdk/6.0.96', |
| 430 | + expected: true, |
| 431 | + }, |
| 432 | + // Unsupported Godot SDK, as it generated project.assets.json in a subfolder of .godot and requires mono. |
| 433 | + { |
| 434 | + targetFramework: 'net9.0', |
| 435 | + projectSdk: 'Godot.NET.Sdk/4.3.0', |
| 436 | + expected: false, |
| 437 | + }, |
| 438 | + // Missing SDK is unsupported, as it defines how and where msbuild generates project.assets.json. |
| 439 | + { |
| 440 | + targetFramework: 'net9.0', |
| 441 | + projectSdk: undefined, |
| 442 | + expected: false, |
| 443 | + }, |
| 444 | + ])( |
| 445 | + 'is v3 graph generation supported for: $targetFramework + $projectSdk', |
| 446 | + async ({ targetFramework, projectSdk, expected }) => { |
| 447 | + expect( |
| 448 | + isSupportedByV3GraphGeneration(targetFramework, projectSdk), |
| 449 | + ).toEqual(expected); |
| 450 | + }, |
| 451 | + ); |
| 452 | +}); |
0 commit comments