4

I have simple asp.net core project. I want to deploy it via TeamCity to IIS. The problem is that I can't setup ASPNETCORE_ENVIRONMENT when publishing the project. My goal is to use default behaviour to load appsettings files:

.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

I use .csproj instead of project.json and Web.config's section related to configuration looks like:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'prod-zone-a|AnyCPU' ">
    <IntermediateOutputPath>obj\Debug\netcoreapp1.1</IntermediateOutputPath>
    <DebugSymbols>true</DebugSymbols>
    <Optimize>false</Optimize>
    <DefineConstants>TRACE;DEBUG;NETCOREAPP1_1</DefineConstants>
</PropertyGroup>

Publish is executed like:

dotnet publish --configuration prod-zone-a --output <some-dir>

Also it's necessary to have several site on IIS published with different configurations: prod-zone-a, prod-zone-b, etc (corresponded appsettings.{env.EnvironmentName}.json looks different too)

How can I implement such idea? Or probably I should to throw this idea out and follow another way?

Update:

According to MS docs I've added separate build step to TeamCity (powershell command):

$Env:ASPNETCORE_ENVIRONMENT = "prod-zone-a"

but it doesn't work.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
user1820686
  • 2,008
  • 5
  • 25
  • 44
  • Haven't worked w/ team city in a while but you need to execute: ```set ASPNETCORE_ENVIRONMENT=prod-zone-a``` via a command line task BEFORE 'dotnet publish'. Then you need to make sure that you have the applicabale 'appsettings.prod-zone-a.json' file as part of your project. – trevorc Mar 28 '17 at 00:40

1 Answers1

1

The only way I found (quite different to this question) is to use web.config transformations that way (another my question on SO)

The main reason is that it's necessary not just publish the project with necessary ASPNETCORE_ENVIRONMENT value, but this value is also needed in application runtime on IIS

Community
  • 1
  • 1
user1820686
  • 2,008
  • 5
  • 25
  • 44