Will Comeaux
Will Comeaux

Reputation: 365

Azure Devops Publish - Wrong AppSettings.JSON is Published

In my repo I have a .net 5 web application project that (for now) references another library that is setup as an executable also. Both of these project have their own appsettings.json. When I publish, I notice that the appsettings.json that ends up in the final folder is always the one from the project being referenced and not the one from the project actually being published. This seems truly odd behavior.

I realize the "right" approach is for the web app to not directly reference the other exe project (already have a story to fix that), but it is still a current concern.

Is there a command argument to have publish prefer appsettings.json from the project being published, as opposed to what seems like arbitrarily selecting one of multiple (or preferring the file from a lower dependency)?

For now, I suspect I can add an additional step to my build to copy the correct config file into place before the publish is "complete", but hoping for a better solution (one that doesn't require extra copy file steps).

Upvotes: 0

Views: 773

Answers (1)

Leo Liu
Leo Liu

Reputation: 76730

Is there a command argument to have publish prefer appsettings.json from the project being published, as opposed to what seems like arbitrarily selecting one of multiple (or preferring the file from a lower dependency)?

The best solution is definitely to find the cause of this issue.

For example, if I add following setting in the project file actually being published:

  <ItemGroup>
    <Content Update="appsettings.json" CopyToPublishDirectory="Never" />
  </ItemGroup>

Then the dotnet will publish the file appsettings.json from the project being referenced.

Of course, the cause of your problem may be other possibilities, which requires more actual information about your project to be able to know.

So, the current solution for this issue, you could add above settings for the project being referenced.

With above setting, the file appsettings.json from the project being referenced will not be published.

Upvotes: 1

Related Questions