question

IhorKuliiev-6228 avatar image
0 Votes"
IhorKuliiev-6228 asked ZhiLv-MSFT answered

Automatically modify Startup.cs and appsettings.json files when Nuget package is installed

Hello!

I am going to create a Nuget package to use within our organization's ASP.NET applications. I need to find out whether it is possible to automatically add some lines of code into the Startup.cs file and a new section into the appsettings.json file once the package is installed.

Thank you in advance!

dotnet-aspnet-core-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ZhiLv-MSFT avatar image
1 Vote"
ZhiLv-MSFT answered

Hi @IhorKuliiev-6228,

I am going to create a Nuget package to use within our organization's ASP.NET applications. I need to find out whether it is possible to automatically add some lines of code into the Startup.cs file and a new section into the appsettings.json file once the package is installed.

It is not possible. As we all known, a Nuget package contains compiled code (as DLLs) along with other content needed in the projects that consume these packages. Before the Nuget package publish to the nuget.org, it has been compiled. So, when installed them, it will not update the Startup.cs file and the Appsettings.json file.

And most importantly, this is not safe to automatically modify the configuration when installed the package.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Best regards,
Dillion

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.