Reputation: 1
I am developing Asp.Net Core 3.1 API, It's working as expected.
When I run it automatically converts the original web.config to a new one.
Original Web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\EngageAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
New web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="COMPLUS_ForceENC" value="1" />
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
So I have two questions.
Update:
Adding more clarification to the question:
why is it causing the issue? I am doing the deployment from azure dev ops. and what I do I copy the web.config from my project to the package which I am creating. and noted this web.config is modified to the new web.config (which has %LAUNCHER_PATH% %LAUNCHER_ARGS%) when you run the code from VS. So basically we don't need to copy this web.config. instead of this, we need to copy the one which gets generated in the publish folder.
CsProj file
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.7" />
<PackageReference Include="Microsoft.Azure.Storage.Common" Version="11.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.1.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
</ItemGroup>
</Project>
Upvotes: 3
Views: 4795
Reputation: 124
Visual Studio will automatically update the web.config file according to your launchsettings.json. It will do so when you run/debug from the IDE or when using dotnet run. Therefore the answer as of net6.0 and VS2022 would be to modify your launch setting profiles so that it stops changing your file on you.
Here is an example
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"ancmHostingModel": "OutOfProcess"
},
The processPath is calculated automatically, but I believe it's possible to specify your own. The process hosting model can be set here too.
Perhaps you'll want each developer to have their own launchsettings.json to suit their environments.
When you publish your project, it will again change your web.config. This behaviour can be disabled if you know you have all the right settings with this .csproj property
<IsWebConfigTransformDisabled>true</ IsWebConfigTransformDisabled>
The web.config can be controlled with transforms at build/publish time, but when running/debugging from Visual Studio (or dotnet run) it will always override your transforms based on the launchsettings :)
Upvotes: 0
Reputation: 2388
Seems like you're using IIS instead of IIS express when debugging.
Try adding this to your .csproj file:
<ANCMPreConfiguredForIIS>true</ANCMPreConfiguredForIIS>
Also make sure your VS version >= VS 16.6.3
This was an issue which has now been fixed by the websdk team: https://github.com/dotnet/websdk/issues/564#issuecomment-644199581
Upvotes: 4