I have an .sln referencing a single .csproj. Inside the .csproj I download static dependencies into ASP.NET's wwwroot:
<Target Name="DownloadContentFiles" BeforeTargets="Restore">
<DownloadFile SourceUrl="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" DestinationFolder="$(MSBuildProjectDirectory)/wwwroot/bootstrap/css/">
<Output TaskParameter="DownloadedFile" ItemName="Content" />
</DownloadFile>
</Target>
My production dockerfile attempts to download all deps (including bootstrap) with dotnet restore on the solution file:
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY *.sln .
COPY FooProject/*.csproj ./FooProject/
RUN dotnet restore
Unfortunately, only the dotnet deps are downloaded, and my DownloadContentFiles target is ignored. However, if I add
RUN cd FooProject && dotnet restore
to my dockerfile, the file is downloaded as expected. Am I missing something obvious? Shouldn't a dotnet restore on a solution behave like individual restores on the solution's members?
I have checked dotnet restore's documentation, but no options appear to be helpful in this regard.
dotnet restore on a solution does not trigger project-level BeforeTargets="Restore" hooks.
It only triggers a package restore operation, ignoring other custom MSBuild logic.
To run your download logic, invoke restore on the individual project or invoke your custom target explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With