Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C# getting started #1179

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions docs/build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,24 @@ echo "Copying generated reference documentation..."
rm -fr ${refdocsdir}/
mkdir -p ${refdocsdir}

if [ ! -d "${refsrc}" ]; then
echo "Cannot find ${refsrc} in the root directory of this repo"
echo "Did you run ./pack.sh?"

if [ -z "${BUILD_DOCS_DEV:-}" ]; then
echo "Cannot build docs without reference. Set BUILD_DOCS_DEV=1 to allow this for development purposes"
exit 1
if [ -z "${BUILD_DOCS_DEV:-}" ]; then
if [ ! -d "${refsrc}" ]; then
echo "Cannot find ${refsrc} in the root directory of this repo"
echo "Did you run ./pack.sh?"

if [ -z "${BUILD_DOCS_DEV:-}" ]; then
echo "Cannot build docs without reference. Set BUILD_DOCS_DEV=1 to allow this for development purposes"
exit 1
fi
else
echo "BUILD_DOCS_DEV is set, continuing without reference documentation..."
rsync -av ${refsrc}/ ${refdocsdir}/

echo "Generating reference docs toctree under ${refs_index}..."
cat ${refs_index}.template > ${refs_index}
ls -1 ${refdocsdir} | grep '.rst$' | sed -e 's/\.rst//' | sort | xargs -I{} echo " ${refdocs}/{}" >> ${refs_index}
fi
else
rsync -av ${refsrc}/ ${refdocsdir}/

echo "Generating reference docs toctree under ${refs_index}..."
cat ${refs_index}.template > ${refs_index}
ls -1 ${refdocsdir} | grep '.rst$' | sed -e 's/\.rst//' | sort | xargs -I{} echo " ${refdocs}/{}" >> ${refs_index}
echo "BUILD_DOCS_DEV is set, continuing without reference documentation..."
fi

export CDK_VERSION=$(../tools/pkgtools/bin/cdk-version)
Expand Down
154 changes: 154 additions & 0 deletions docs/src/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ Create an empty project structure for the |cdk| app.

.. tabs::

.. group-tab:: C#

Create a new empty, source controlled directory and then create a new
console application.

.. code-block:: sh

mkdir HelloCdk
cd HelloCdk
dotnet new console

.. group-tab:: JavaScript

Create an empty source-controlled directory for your project and an
Expand Down Expand Up @@ -148,6 +159,14 @@ library includes the basic classes needed to write |cdk| stacks and apps.

.. tabs::

.. group-tab:: C#

Install the **Amazon.CDK NuGet** package:

.. code-block:: sh

dotnet add package Amazon.CDK

.. group-tab:: JavaScript

Install the **@aws-cdk/cdk** package:
Expand Down Expand Up @@ -189,6 +208,26 @@ class. Let's create our first, empty **App**:

.. tabs::

.. group-tab:: C#

In **Program.cs**

.. code-block:: c#

using Amazon.CDK;

namespace HelloCdk
{
class Program
{
static void Main(string[] args)
{
var myApp = new App();
myApp.Run();
}
}
}

.. group-tab:: JavaScript

In **index.js**:
Expand Down Expand Up @@ -256,6 +295,14 @@ If needed, compile the code:

.. tabs::

.. group-tab:: C#

Compile the code using your IDE or via the dotnet CLI:

.. code-block:: sh

dotnet build

.. group-tab:: JavaScript

No need to compile
Expand Down Expand Up @@ -323,6 +370,16 @@ your project directory:

.. tabs::

.. group-tab:: C#

Define the :code:`--app` option in a **cdk.json** file:
costleya marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: json

{
"app": "dotnet run --project HelloCdk.csproj"
}

.. group-tab:: JavaScript

Define the :code:`--app` option in **cdk.json** to execute **index.js**
Expand Down Expand Up @@ -431,6 +488,44 @@ Define a stack and add it to the app.

.. tabs::

.. group-tab:: C#

Create **MyStack.cs**:

.. code-block:: c#

using Amazon.CDK;

namespace HelloCdk
{
public class MyStack: Stack
{
public MyStack(App parent, string name) : base(parent, name, new StackProps())
costleya marked this conversation as resolved.
Show resolved Hide resolved
{
}
}
}

In **Program.cs**:

.. code-block:: c#
:emphasize-lines: 10

using Amazon.CDK;

namespace HelloCdk
{
class Program
{
static void Main(string[] args)
{
var myApp = new App();
new MyStack(myApp, "hello-cdk");
myApp.Run();
}
}
}

.. group-tab:: JavaScript

In **index.js**:
Expand Down Expand Up @@ -539,6 +634,12 @@ Compile your program:

.. tabs::

.. group-tab:: C#

We have configured cdk.json to run "dotnet run", which will
restore dependencies, build, and run your application.
Therefore, you just need to run the CDK command.

.. group-tab:: JavaScript

Nothing to compile.
Expand Down Expand Up @@ -586,6 +687,12 @@ Install the **@aws-cdk/aws-s3** package:

.. tabs::

.. group-tab:: C#

.. code-block:: sh

dotnet add package Amazon.CDK.AWS.S3

.. group-tab:: JavaScript

.. code-block:: sh
Expand Down Expand Up @@ -615,6 +722,30 @@ the :py:class:`Bucket <@aws-cdk/aws-s3.Bucket>` class:

.. tabs::

.. group-tab:: C#

Create **MyStack.cs**:
costleya marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: c#
:emphasize-lines: 2,10,11,12,13

using Amazon.CDK;
using Amazon.CDK.AWS.S3;

namespace HelloCdk
{
public class MyStack : Stack
{
public MyStack(App parent, string name) : base(parent, name, new StackProps())
{
new Bucket(this, "MyFirstBucket", new BucketProps
{
Versioned = true
});
}
}
}

.. group-tab:: JavaScript

In **index.js**:
Expand Down Expand Up @@ -698,6 +829,12 @@ Compile your program:

.. tabs::

.. group-tab:: C#

We have configured cdk.json to run "dotnet run", which will
restore dependencies, build, and run your application.
Therefore, you just need to run the CDK command.

.. group-tab:: JavaScript

Nothing to compile.
Expand Down Expand Up @@ -777,6 +914,17 @@ Configure the bucket to use KMS managed encryption:

.. tabs::

.. group-tab:: C#

.. code-block:: c#
:emphasize-lines: 4

new Bucket(this, "MyFirstBucket", new BucketProps
{
Versioned = true,
Encryption = BucketEncryption.KmsManaged
});

.. group-tab:: JavaScript

.. code-block:: js
Expand Down Expand Up @@ -811,6 +959,12 @@ Compile the program:

.. tabs::

.. group-tab:: C#

We have configured cdk.json to run "dotnet run", which will
restore dependencies, build, and run your application.
Therefore, you just need to run the CDK command.

.. group-tab:: JavaScript

Nothing to compile.
Expand Down