Common Steps
Publish Sample
ASP.NET Core
Use the dotnet
CLI to build and locally publish the application for the framework and runtime you will deploy the application to:
- Linux with .NET Core:
dotnet publish -f netcoreapp3.1 -r linux-x64
- Windows with .NET Core:
dotnet publish -f netcoreapp3.1 -r win10-x64
- Windows with .NET Platform:
dotnet publish -f net461 -r win10-x64
NOTE: Starting with .NET Core 2.0, the
dotnet publish
command will automatically restore dependencies for you. Runningdotnet restore
explicitly is not generally required.
ASP.NET 4.x
- Open the solution for the sample in Visual Studio
- Right click on the project, select "Publish"
- Use the included
FolderProfile
to publish tobin/Debug/net461/win10-x64/publish
Cloud Foundry Push Sample
Use the Cloud Foundry CLI to push the published application to Cloud Foundry using the parameters that match what you selected for framework and runtime:
# Push to Linux cell
cf push -f manifest.yml -p bin/Debug/netcoreapp3.1/linux-x64/publish
# Push to Windows cell, .NET Core
cf push -f manifest-windows.yml -p bin/Debug/netcoreapp3.1/win10-x64/publish
# Push to Windows cell, .NET Framework
cf push -f manifest-windows.yml -p bin/Debug/net461/win10-x64/publish
NOTE: all sample manifests have been defined to bind their application to their service(s) as created above.
Observe Logs
To see the logs as you startup the application, use cf logs oauth
.
On a Linux cell, you should see something resembling the following during startup:
2016-06-01T09:14:14.38-0600 [CELL/0] OUT Creating container
2016-06-01T09:14:15.93-0600 [CELL/0] OUT Successfully created container
2016-06-01T09:14:17.14-0600 [CELL/0] OUT Starting health monitoring of container
2016-06-01T09:14:21.04-0600 [APP/0] OUT Hosting environment: Development
2016-06-01T09:14:21.04-0600 [APP/0] OUT Content root path: /home/vcap/app
2016-06-01T09:14:21.04-0600 [APP/0] OUT Now listening on: http://*:8080
2016-06-01T09:14:21.04-0600 [APP/0] OUT Application started. Press Ctrl+C to shut down.
2016-06-01T09:14:21.41-0600 [CELL/0] OUT Container became healthy
On Windows cells, you should see something slightly different but with the same information.
Reading Configuration Values
Once the connector's settings have been defined, the next step is to read them so that they can be made available to the connector.
The code in the next example reads connector settings from the appsettings.json
file with the .NET JSON configuration provider (AddJsonFile("appsettings.json"))
and from VCAP_SERVICES
with AddCloudFoundry()
. Both sources are then added to the configuration builder. The following code shows how to read from both sources:
public class Program {
...
public static IWebHost BuildWebHost(string[] args)
{
return new WebHostBuilder()
...
.UseCloudHosting()
...
.ConfigureAppConfiguration((builderContext, configBuilder) =>
{
var env = builderContext.HostingEnvironment;
configBuilder.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables()
// Add to configuration the Cloudfoundry VCAP settings
.AddCloudFoundry();
})
.Build();
}
...
When pushing the application to Cloud Foundry, the settings from service bindings merge with the settings from other configuration mechanisms (such as appsettings.json
).
If there are merge conflicts, the last provider added to the Configuration takes precedence and overrides all others.
To manage application settings centrally instead of with individual files, use Steeltoe Configuration and a tool such as Spring Cloud Config Server
NOTE: If you use the Spring Cloud Config Server,
AddConfigServer()
automatically callsAddCloudFoundry()
for you.