Skip to content

Commit 2915ac1

Browse files
costleyaDoug-AWS
authored andcommitted
feat(docs): getting started instructions for csharp (#1185)
* chore(build): Always ignore reference docs on flag set. Even if the reference source directory exists, it takes a long time to copy the files. Deleting this directory is not preferable since the generation toime is also long. Therefore, setting the flag will now always skip reference file copying on the BUILD_DOCS_DEV variable being set. * feature(docs): Add getting started documentation for C#. Fixes #696
1 parent c7b1004 commit 2915ac1

File tree

2 files changed

+169
-13
lines changed

2 files changed

+169
-13
lines changed

docs/build-docs.sh

+15-13
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,24 @@ echo "Copying generated reference documentation..."
5959
rm -fr ${refdocsdir}/
6060
mkdir -p ${refdocsdir}
6161

62-
if [ ! -d "${refsrc}" ]; then
63-
echo "Cannot find ${refsrc} in the root directory of this repo"
64-
echo "Did you run ./pack.sh?"
65-
66-
if [ -z "${BUILD_DOCS_DEV:-}" ]; then
67-
echo "Cannot build docs without reference. Set BUILD_DOCS_DEV=1 to allow this for development purposes"
68-
exit 1
62+
if [ -z "${BUILD_DOCS_DEV:-}" ]; then
63+
if [ ! -d "${refsrc}" ]; then
64+
echo "Cannot find ${refsrc} in the root directory of this repo"
65+
echo "Did you run ./pack.sh?"
66+
67+
if [ -z "${BUILD_DOCS_DEV:-}" ]; then
68+
echo "Cannot build docs without reference. Set BUILD_DOCS_DEV=1 to allow this for development purposes"
69+
exit 1
70+
fi
6971
else
70-
echo "BUILD_DOCS_DEV is set, continuing without reference documentation..."
72+
rsync -av ${refsrc}/ ${refdocsdir}/
73+
74+
echo "Generating reference docs toctree under ${refs_index}..."
75+
cat ${refs_index}.template > ${refs_index}
76+
ls -1 ${refdocsdir} | grep '.rst$' | sed -e 's/\.rst//' | sort | xargs -I{} echo " ${refdocs}/{}" >> ${refs_index}
7177
fi
7278
else
73-
rsync -av ${refsrc}/ ${refdocsdir}/
74-
75-
echo "Generating reference docs toctree under ${refs_index}..."
76-
cat ${refs_index}.template > ${refs_index}
77-
ls -1 ${refdocsdir} | grep '.rst$' | sed -e 's/\.rst//' | sort | xargs -I{} echo " ${refdocs}/{}" >> ${refs_index}
79+
echo "BUILD_DOCS_DEV is set, continuing without reference documentation..."
7880
fi
7981

8082
export CDK_VERSION=$(../tools/pkgtools/bin/cdk-version)

docs/src/getting-started.rst

+154
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ Create an empty project structure for the |cdk| app.
7777
7878
.. tabs::
7979

80+
.. group-tab:: C#
81+
82+
Create a new empty, source controlled directory and then create a new
83+
console application.
84+
85+
.. code-block:: sh
86+
87+
mkdir HelloCdk
88+
cd HelloCdk
89+
dotnet new console
90+
8091
.. group-tab:: JavaScript
8192

8293
Create an empty source-controlled directory for your project and an
@@ -192,6 +203,14 @@ library includes the basic classes needed to write |cdk| stacks and apps.
192203

193204
.. tabs::
194205

206+
.. group-tab:: C#
207+
208+
Install the **Amazon.CDK NuGet** package:
209+
210+
.. code-block:: sh
211+
212+
dotnet add package Amazon.CDK
213+
195214
.. group-tab:: JavaScript
196215

197216
Install the **@aws-cdk/cdk** package:
@@ -232,6 +251,26 @@ class. Create an empty **App**:
232251

233252
.. tabs::
234253

254+
.. group-tab:: C#
255+
256+
In **Program.cs**
257+
258+
.. code-block:: c#
259+
260+
using Amazon.CDK;
261+
262+
namespace HelloCdk
263+
{
264+
class Program
265+
{
266+
static void Main(string[] args)
267+
{
268+
var myApp = new App();
269+
myApp.Run();
270+
}
271+
}
272+
}
273+
235274
.. group-tab:: JavaScript
236275

237276
Create the file **bin/hello-cdk.js**:
@@ -293,6 +332,14 @@ If needed, compile the code:
293332

294333
.. tabs::
295334

335+
.. group-tab:: C#
336+
337+
Compile the code using your IDE or via the dotnet CLI:
338+
339+
.. code-block:: sh
340+
341+
dotnet build
342+
296343
.. group-tab:: JavaScript
297344

298345
No need to compile
@@ -358,6 +405,16 @@ your project directory with the following content:
358405

359406
.. tabs::
360407

408+
.. group-tab:: C#
409+
410+
Define the :code:`--app` option in a **cdk.json** file:
411+
412+
.. code-block:: json
413+
414+
{
415+
"app": "dotnet run --project HelloCdk.csproj"
416+
}
417+
361418
.. group-tab:: JavaScript
362419

363420
Define the :code:`--app` option in **cdk.json** to execute **hello-cdk.js**
@@ -466,6 +523,44 @@ Define a stack and add it to the app.
466523

467524
.. tabs::
468525

526+
.. group-tab:: C#
527+
528+
Create **MyStack.cs**:
529+
530+
.. code-block:: c#
531+
532+
using Amazon.CDK;
533+
534+
namespace HelloCdk
535+
{
536+
public class MyStack: Stack
537+
{
538+
public MyStack(App parent, string name) : base(parent, name, null)
539+
{
540+
}
541+
}
542+
}
543+
544+
In **Program.cs**:
545+
546+
.. code-block:: c#
547+
:emphasize-lines: 10
548+
549+
using Amazon.CDK;
550+
551+
namespace HelloCdk
552+
{
553+
class Program
554+
{
555+
static void Main(string[] args)
556+
{
557+
var myApp = new App();
558+
new MyStack(myApp, "hello-cdk");
559+
myApp.Run();
560+
}
561+
}
562+
}
563+
469564
.. group-tab:: JavaScript
470565

471566
In **index.js**:
@@ -575,6 +670,12 @@ Compile your program:
575670

576671
.. tabs::
577672

673+
.. group-tab:: C#
674+
675+
We have configured cdk.json to run "dotnet run", which will
676+
restore dependencies, build, and run your application.
677+
Therefore, you just need to run the CDK command.
678+
578679
.. group-tab:: JavaScript
579680

580681
Nothing to compile.
@@ -622,6 +723,12 @@ Install the **@aws-cdk/aws-s3** package:
622723

623724
.. tabs::
624725

726+
.. group-tab:: C#
727+
728+
.. code-block:: sh
729+
730+
dotnet add package Amazon.CDK.AWS.S3
731+
625732
.. group-tab:: JavaScript
626733

627734
.. code-block:: sh
@@ -651,6 +758,30 @@ the :py:class:`Bucket <@aws-cdk/aws-s3.Bucket>` class:
651758

652759
.. tabs::
653760

761+
.. group-tab:: C#
762+
763+
Create **MyStack.cs**:
764+
765+
.. code-block:: c#
766+
:emphasize-lines: 2,10,11,12,13
767+
768+
using Amazon.CDK;
769+
using Amazon.CDK.AWS.S3;
770+
771+
namespace HelloCdk
772+
{
773+
public class MyStack : Stack
774+
{
775+
public MyStack(App parent, string name) : base(parent, name, null)
776+
{
777+
new Bucket(this, "MyFirstBucket", new BucketProps
778+
{
779+
Versioned = true
780+
});
781+
}
782+
}
783+
}
784+
654785
.. group-tab:: JavaScript
655786

656787
In **index.js**:
@@ -739,6 +870,12 @@ Compile your program:
739870

740871
.. tabs::
741872

873+
.. group-tab:: C#
874+
875+
We have configured cdk.json to run "dotnet run", which will
876+
restore dependencies, build, and run your application.
877+
Therefore, you just need to run the CDK command.
878+
742879
.. group-tab:: JavaScript
743880

744881
Nothing to compile.
@@ -818,6 +955,17 @@ Configure the bucket to use KMS managed encryption:
818955

819956
.. tabs::
820957

958+
.. group-tab:: C#
959+
960+
.. code-block:: c#
961+
:emphasize-lines: 4
962+
963+
new Bucket(this, "MyFirstBucket", new BucketProps
964+
{
965+
Versioned = true,
966+
Encryption = BucketEncryption.KmsManaged
967+
});
968+
821969
.. group-tab:: JavaScript
822970

823971
.. code-block:: js
@@ -852,6 +1000,12 @@ Compile the program:
8521000

8531001
.. tabs::
8541002

1003+
.. group-tab:: C#
1004+
1005+
We have configured cdk.json to run "dotnet run", which will
1006+
restore dependencies, build, and run your application.
1007+
Therefore, you just need to run the CDK command.
1008+
8551009
.. group-tab:: JavaScript
8561010

8571011
Nothing to compile.

0 commit comments

Comments
 (0)