Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pre-configure my .NET Core 1.1 app's published web.config file

I have an MVC project that is targeting .NETCoreApp 1.1. When I publish the project, a web.config file is created for me. I want the created web.config to contain a few rewrite rules.

I've tried adding a web.config file to the project root, but every publish attempt contains the same generic, mostly empty configuration file. Where/how do I get the publish process to include a web.config that contains my extra information?

Edit:

It looks like this may not be an issue with dotnet core's publish. This may be an issue to how I've configured my TeamCity build.

  • Works when using a local folder publish from VS 2017
  • Works running the following CLI command: (same as what's used in TC)
    • dotnet publish .\{{projectName}}.csproj --configuration Staging --output C:\new-output-dir\
like image 318
Daniel Brown Avatar asked Jan 22 '26 03:01

Daniel Brown


1 Answers

@Dmitry's comment lead me down the right path.

I hopped into TeamCity's build logs to see what command was being executed to publish my app. It looked similar to:

dotnet publish .\{{projectName}}.csproj --configuration Staging --output C:\new-output-dir\

TeamCity was re-using the output directory for each build, and by default the previous web.configs that had been generated weren't being overwritten with the new one that contained the rewrite rules.

Two possible solutions:

  • Use a new output directory per build
  • Clear or force overwrite files in existing output directories
    • Use dotnet clean command

Resources for learning more:

  • Official dotnet publish documentation
  • Quick notes on dotnet publish command
like image 155
Daniel Brown Avatar answered Jan 23 '26 19:01

Daniel Brown