0
votes

I have a dot net core 3.1 project. When I run my application using IIS it creates a web.config file automatically by adding environment ASPNETCORE_ENVIRONMENT" = "Development". Since I am deploying my application to Azure and managing configuration via application settings, I don't need to publish the web.config file in my artifact folder. Also, the added ASPNETCORE_ENVIRONMENT causes change the ASPNETCORE_ENVIRONMENT from Staging/Production to Development as well. I wanted to exclude the web.config while publishing. I have tried with different approaches suggested online but nothing works like:

    <ItemGroup>
        <Content Remove="web.config" />
    </ItemGroup>

    <ItemGroup>
        <Content Update="web.config">
            <CopyToOutputDirectory>Never</CopyToOutputDirectory>
        </Content>
    </ItemGroup>

    <ItemGroup>
        <Content Update="web.config">
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </Content>
    </ItemGroup>

But it always includes the web.config file in published directory for dotnet publish command. Is there anything I am missing here?

1

1 Answers

0
votes

According to this github issue, you should add the following section in the .csproj

<PropertyGroup>
  <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>