【发布时间】:2022-01-22 02:45:25
【问题描述】:
我刚刚从此处“https://docs.aws.amazon.com/cdk/api/v1/dotnet/api/Amazon.CDK.AWS.EC2.CfnSecurityGroup. html”
但是当我尝试合成/部署时,我收到了这个错误
错误 CS0246:找不到类型或命名空间名称“IngressProperty”(您是否缺少 using 指令或程序集引用?
似乎文档本身不可靠或不工作。
using Amazon.CDK;
using Constructs;
using Amazon.CDK.AWS.EC2;
namespace Sg
{
public class SgStack : Stack
{
internal SgStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
{
var cfnSecurityGroup = new CfnSecurityGroup(this, "MyCfnSecurityGroup", new CfnSecurityGroupProps {
GroupDescription = "test",
GroupName = "test",
SecurityGroupIngress = new [] { new IngressProperty {
IpProtocol = "tcp",
CidrIp = "0.0.0.0/0",
Description = "description",
FromPort = 22,
ToPort = 22
} },
VpcId = "vpc-12345"
});
}
}
}
【问题讨论】:
-
您在参考 v1 文档时可能正在使用 v2 API DLL。
-
我刚刚尝试了 v1 和 v2 但得到了同样的错误。
-
进行了清理以测试 v1 并收到此错误命名空间“Amazon.CDK”中不存在类型或命名空间名称“AWS”
标签: c# amazon-web-services aws-cdk aws-security-group