Home > OS >  AWS CDK: Detected package version outside of dependency constraint
AWS CDK: Detected package version outside of dependency constraint

Time:01-04

I am currently working on AWS moderization workshop. When I add the Amazon.CDK.AWS.EC2 nuget library and build the application, I get the following errors: The application uses the latest Amazon. CDK.Lib, Contructs, Amazon.CDK.AWS.EC2 libraries from Nuget. I have also tried to run the command npm update -g aws-cdk using troubleshooting steps documented in https://docs.aws.amazon.com/cdk/v2/guide/troubleshooting.html#troubleshooting_toolkit but that has not helped.

What am I missing?

Build errors:

Rebuild started...
1>------ Rebuild All started: Project: NorthwindCdk, Configuration: Debug Any CPU ------
Restored C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj (in 54 ms).
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.EC2 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.CloudWatch 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.IAM 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.KMS 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.Logs 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.S3.Assets 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.S3 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.SSM 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.Assets 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdk.csproj : warning NU1608: Detected package version outside of dependency constraint: Amazon.CDK.AWS.Events 1.137.0 requires Constructs (>= 3.3.69 && < 4.0.0) but version Constructs 10.0.22 was resolved.
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdkStack.cs(7,38,7,43): error CS0433: The type 'Stack' exists in both 'Amazon.CDK.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Amazon.CDK, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdkStack.cs(9,36,9,45): error CS0104: 'Construct' is an ambiguous reference between 'Amazon.CDK.Construct' and 'Constructs.Construct'
1>C:\Users\12146\northwind-cdk\src\NorthwindCdk\NorthwindCdkStack.cs(9,64,9,75): error CS0433: The type 'IStackProps' exists in both 'Amazon.CDK.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Amazon.CDK, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
1>Done building project "NorthwindCdk.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

NorthwindCdk.cs:

using Amazon.CDK;
using Constructs;
using Amazon.CDK.AWS.EC2;

namespace NorthwindCdk
{
    public class NorthwindCdkStack : Stack
  {
        internal NorthwindCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
      var vpc = new Vpc(this, "LabVpc", new VpcProps
      {
        MaxAzs = 2
      });
    }
    }
}

CodePudding user response:

it seems that the Amazon.CDK.AWS.EC2 nuget library is deprecated. I uninstalled the library and the application build and deployed correctly.

CodePudding user response:

This is caused by the fact that you have both CDK v1 and v2 installed. In CDKv1, each module is its own package - the packages that are included in the error are all v1 (e.g.Amazon.CDK.AWS.EC2, Amazon.CDK.AWS.Cloudwatch, etc). With CDKv2, all these modules are included in the Amazon.CDK.Lib package, which you also have installed.

To be clear, CDKv1 is not deprecated, both are supported. But you cannot use both at the same time.

  •  Tags:  
  • Related