Skip to content

Commit dd52cec

Browse files
gweinholdmergify[bot]
authored andcommitted
feat(net): templatized csharp sample app and moved from init to sample-app. Changed hook code to allow templating. (#3525)
* Templatized csharp init to a base skeleton. * Moved csharp init to sample-app
1 parent 0c806a6 commit dd52cec

18 files changed

+489
-35
lines changed
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
2-
# CDK HelloWorld
3-
4-
Welcome to your CDK .NET project!
5-
6-
You should explore the contents of this template. It demonstrates a CDK app with two instances of
7-
a stack (`HelloStack`) which also uses a user-defined construct (`HelloConstruct`).
8-
9-
The `cdk.json` file tells the CDK Toolkit how to execute your app. It uses the `dotnet` CLI to do this.
10-
111
# Useful commands
122

133
* `dotnet build src` compile this app
14-
* `cdk ls` list all stacks in the app
15-
* `cdk synth` emits the synthesized CloudFormation template
164
* `cdk deploy` deploy this stack to your default AWS account/region
175
* `cdk diff` compare deployed stack with current state
18-
* `cdk docs` open CDK documentation
19-
20-
Enjoy!
6+
* `cdk synth` emits the synthesized CloudFormation template

packages/aws-cdk/lib/init-templates/app/csharp/add-project.hook.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import * as path from 'path';
33
import { InvokeHook } from '../../../init';
44

55
export const invoke: InvokeHook = async (targetDirectory: string) => {
6-
const slnPath = path.join(targetDirectory, "src", "HelloCdk.sln");
7-
const csprojPath = path.join(targetDirectory, "src", "HelloCdk", "HelloCdk.csproj");
6+
const slnPath = path.join(targetDirectory, "src", "%name.PascalCased%.sln");
7+
const csprojPath = path.join(targetDirectory, "src", "%name.PascalCased%", "%name.PascalCased%.csproj");
88

99
const child = child_process.spawn('dotnet', [ 'sln', slnPath, 'add', csprojPath ], {
1010
// Need this for Windows where we want .cmd and .bat to be found as well.
@@ -26,7 +26,7 @@ export const invoke: InvokeHook = async (targetDirectory: string) => {
2626
if (code === 0) {
2727
resolve(Buffer.concat(stdout).toString('utf-8'));
2828
} else {
29-
reject(new Error(`Could not add project HelloCdk.csproj to solution HelloCdk.sln. Error code: ${code}`));
29+
reject(new Error(`Could not add project %name.PascalCased%.csproj to solution %name.PascalCased%.sln. Error code: ${code}`));
3030
}
3131
});
3232
});

packages/aws-cdk/lib/init-templates/app/csharp/cdk.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"app": "dotnet src/%name.PascalCased%/bin/Debug/netcoreapp2.1/%name.PascalCased%.dll"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Amazon.CDK;
2+
3+
namespace %name.PascalCased%
4+
{
5+
public class %name.PascalCased%Stack : Stack
6+
{
7+
public %name.PascalCased%Stack(Construct parent, string id, IStackProps props) : base(parent, id, props)
8+
{
9+
// The code that defines your stack goes here
10+
}
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Amazon.CDK;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace %name.PascalCased%
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
var app = new App(null);
13+
new %name.PascalCased%Stack(app, "%name.PascalCased%Stack", new StackProps());
14+
app.Synth();
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)