Reputation: 2347
I am doing the following to build my application:
dotnet build MyApp.sln -c Release
dotnet test MyApp.sln --no-build -c Release
dotnet publish MyApp.csproj --no-build -c Release -r win-x64
The aim is to, build the whole solution once, including the test projects. Run the tests, and if they pass, to publish the endpoint app into a specific runtime. I don't want to rebuild anything once the first step is complete.
But doing so, I am getting the following error:
C:\Program Files\dotnet\sdk\8.0.205\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5) : error NETSDK1047: Assets file 'MyApp\obj\project.assets.json' doesn't have a target for 'net8.0-windows/win-x64'. Ensure that restore has run and that you have included 'net8.0-windows' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers. [MyApp.csproj]
Here is my csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>
</Project>
If I set the runtime, it works. But I don't understand the point of the publish if everything is already set in stone in the csproj?
I also tried to perform a dotnet restore MyApp.csproj -r win-x64
between the build and the publish. It worked slightly better (I have a publish folder under bin/Release/net8.0-windows/win-x64
and it looks like everything is in), but gave me another error:
C:\Program Files\dotnet\sdk\8.0.205\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(351,5): error MSB3030: Could not copy the file "MyApp\bin\Release\net8.0-windows\win-x64\MyApp.runtimeconfig.json" because it was not found. [MyApp.csproj]
C:\Program Files\dotnet\sdk\8.0.205\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(351,5): error MSB3030: Could not copy the file "MyApp\bin\Release
net8.0-windows\win-x64\MyApp.deps.json" because it was not found. [MyApp.csproj]C:\Program Files\dotnet\sdk\8.0.205\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(351,5): error MSB3030: Could not copy the file "bin\Release\net8.0-windows\win-x64\MyApp.xml" because it was not found. [MyApp.csproj]
So I know how to fix it (setting the runtimeidentifer into the csproj), but I would like to understand why I have to do this, and what is the point of the publish if I do so?
Upvotes: 3
Views: 1114
Reputation: 27341
Because you specified RID in the publish
command, it requires using the built files in the folder obj/Release/net8.0-windows/win-x64
for packaging and publishing. However you did not specify RID in the build
command, so this folder does not exist, the publish
command naturally failed.
In fact, you don't need to specify --no-build
, because if the files in the obj folder are up-to-date, they won't be rebuilt.
Upvotes: 2