Reputation: 2347
With the following project file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>
</Project>
Here is my undestanding of the situation:
When I build without any runtime specified (dotnet build
), it generates the binaries into bin\release\net8.0-windows
where I have a runtimes
folder that contains all the runtime specific dependencies. When I run my application from this location, it works because it determines which runtime we are on and select the appropriate dependencies into the runtimes folder.
When I build with a specified runtime (dotnet build -r win-x64
for example), the binaries are generated into bin\release\net8.0-windows\win-x64
, without any runtimes
folder because it is runtime dependent. When I run my application from this location, it works only if I am on a windows with the x64 runtime installed.
When I publish with the same runtime (dotnet publish -r win-x64
for example), the binaries are generated into bin\release\net8.0-windows\win-x64\publish
, with an extra web.config
file. Same as the previous case, it can run only in a win-x64 environment.
I thought the publish target was generating a runtime dependent package by keeping the good dependencies within the runtimes folder and getting rid of the other. But according to this question (Why do I have to specify the runtime identifier in the csproj for a publish?), the publish needs some other prerequistes to work properly.
So what are the differences between dotnet build -r win-x64
and dotnet publish -r win-x64
? This extra web.config file isn't even necessary to run the application on the right environment.
Upvotes: 0
Views: 122