How to publish environment specific appsettings in .Net core app?

If someone else is wondering how to use different appsettings for multiple environments here is a possible solution. dotnet publish –configuration [Debug|Release] will copy the appropriate appsettings.json file into the publish folder if *.csproj has a conditional logic for these files: First in the .pubxml publish profile file (can be found in Properties->PublishProfiles of Visual … Read more

dotnet publish doesn´t publish correct appsettings.{env.EnvironmentName}.json

Update: For current (new) .csproj format the CopyToPublishDirectory attribute should be used. It determines whether to copy the file to the publish directory and can have one of the following value: Always, PreserveNewest Never So add next section into your .csproj: <ItemGroup> <None Include=”appsettings.Production.json” CopyToPublishDirectory=”Always” /> </ItemGroup> Look into @nover answer and SO Exclude or … Read more

‘IHostingEnvironment’ is obsolete

It seems IHostingEnvironment has been replaced by IHostEnvironment (and a few others). You should be able to change the interface type in your code and everything will work as it used to 🙂 You can find more information about the changes at this link on GitHub https://github.com/aspnet/AspNetCore/issues/7749 EDIT There is also an additional interface IWebHostEnvironment … Read more

Populate IConfiguration for unit tests

You can use MemoryConfigurationBuilderExtensions to provide it via a dictionary. using Microsoft.Extensions.Configuration; var myConfiguration = new Dictionary<string, string> { {“Key1”, “Value1”}, {“Nested:Key1”, “NestedValue1”}, {“Nested:Key2”, “NestedValue2”} }; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(myConfiguration) .Build(); The equivalent JSON would be: { “Key1”: “Value1”, “Nested”: { “Key1”: “NestedValue1”, “Key2”: “NestedValue2” } } The equivalent Environment Variables would be … Read more

ASP.NET Core 3.0 not showing on Visual Studio 2019

There is an option in Tools -> Options that enables preview versions of the .NET Core SDK. In the VS Preview shipping channel, it is on (by default, and not settable). In the VS Release channel, it defaults to off and you can opt-in. (Note: it’s disabled in the screenshot because I have a Preview … Read more

How to update the model when using database first approach

You can re-scaffold the model by running the command that you originally ran with the -Force option added. That will result in the contents of the specified folder being over-written. Using the Package Manager Console example from the EF Core docs, the revised command becomes: Scaffold-DbContext “Server=(localdb)\v11.0;Database=Blogging;Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force Alternatively, if you are … Read more

Visual Studio 2017 install breaks Visual Studio 2015 ASP.NET Core Projects

@ClaudioNunes and @MegaTron have the correct answer. After reading that answer, I realized my .NET Core solution did not have a global.json file. I added a new solution folder and added a global.json file. Since none of my projects are nested in sub folders, I only had to remove “src” and “test” from the projects … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)