I'm new to docker and i was trying to migrate my API written in .NET 6 from IIS to a Docker.
So i've wrote a Docker file
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
# copy all the layers' csproj files into respective folders
COPY ./VisualOrder.csproj src/
# run restore over API project - this pulls restore over the dependent projects as well
RUN dotnet restore "src/VisualOrder.csproj"
COPY . .
# run build over the API project
WORKDIR "/src/"
RUN dotnet build -c Release -o /app/build
# run publish over the API project
FROM build AS publish
RUN dotnet publish -c Release -o /app/publish
FROM base AS runtime
WORKDIR /app
COPY --from=publish /app/publish .
RUN ls -l
ENTRYPOINT [ "dotnet", "VisualOrder.dll" ]
But the issue is that at RUN dotnet build ... the build fails with the following error:
Restored /src/VisualOrder.csproj (in 338 ms). #15 1.897 /usr/share/dotnet/sdk/6.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(356,5): error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App' was not recognized [/src/VisualOrder.csproj]
I tried to run dotnet restore on my PC by deleting bin and obj folders but on my PC all works as it have to.
.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<SignAssembly>false</SignAssembly>
<UserSecretsId>d96c762d-ae98-4b1d-a27d-af48bb400d26</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Content Remove="bundleconfig.json" />
<Content Remove="Views\Emails\EmailNegozio.cshtml" />
<Content Remove="Views\Emails\EmailRiepilogo.cshtml" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="bundleconfig.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Views\Emails\EmailNegozio.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Views\Emails\EmailRiepilogo.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="bundleconfig.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="MySql.Data" Version="8.0.27" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="PayPalCheckoutSdk" Version="1.0.4" />
<PackageReference Include="PayPalHttp" Version="1.0.1" />
<PackageReference Include="QRCoder" Version="1.4.2" />
<PackageReference Include="RazorEngine.NetCore" Version="3.1.0" />
<PackageReference Include="RestSharp" Version="106.13.0" />
<PackageReference Include="Stripe.net" Version="39.80.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>
I was able to solve the following issue by setting in project properties > output type > class library
by default VisualStudio sets it to 'Console application'.