Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework target thinks build_context == wwwroot #383

Open
davhdavh opened this issue May 19, 2023 · 3 comments
Open

Framework target thinks build_context == wwwroot #383

davhdavh opened this issue May 19, 2023 · 3 comments

Comments

@davhdavh
Copy link

Framework and core targets does not interpret the build context in the same way

Microsoft.Docker.Templates.windows.dotnetframework.aspnet.docker-compose.vs.debug.yml has

volumes:
- $build_context$:C:\inetpub\wwwroot

Microsoft.Docker.Templates.windows.dotnetcore.aspnetcore.docker-compose.vs.debug.yml has

volumes:
  - $app_folder_path$:C:\app
  - $full_build_context$:C:\src

This is a huge problem, because framework targets are unable to include any dockerfile commands that target files outside of the primary source directory, e.g. COPY [ "myutil\myutil.exe", "c:" ].

The proper generated file for framework should be

volumes:
  - $app_folder_path$:C:\inetpub\wwwroot
  - $full_build_context$:C:\src
@davhdavh
Copy link
Author

davhdavh commented May 19, 2023

workaround is quite complex...

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 AS base
WORKDIR /
SHELL ["powershell"]
#move website to c:\app due to visual studio docker https://github.com/microsoft/DockerTools/issues/383
RUN Import-Module WebAdministration; `
    mkdir c:\app; `
    Set-ItemProperty 'IIS:\Sites\Default Web Site' -Name 'physicalPath' -Value 'c:\app';

and in docker-compose.yml add

    volumes:
    - .\myactualwebfolder:C:\app

@NCarlsonMSFT
Copy link
Member

@davhdavh FYI the build context being different is intentional. ASP.NET Core uses the solution as the build context to support building in the container with projects references. The ASP.NET scaffolding published on the host, so it uses the smaller build context of the project folder.

If you need a file from outside your project directory in an ASP.NET project, you can change the build context:
Change the property "context" under your service's build property in docker-compose.yml. When you change it, you need to make sure you update the relative path to your dockerfile, and the relative paths in your Dockerfile. You should also move your .dockerignore file to the new build context and update its relative paths to the new location.

Specific to supporting VS you also need to add a file docker-compose.vs.debug.yml and override the arg source and the volume for C:\inetpub\wwwroot to handle the moved context. Here is an example for my project WebApplication8 having a build context of the solution directory:

services:
  webapplication8:
    build:
      args:
        source: WebApplication8/obj/Docker/empty/
    volumes:
      - .\WebApplication8:C:\inetpub\wwwroot

@davhdavh
Copy link
Author

My point was consistency... The core docker is vastly different from the framework one.
Your workaround doesn't work, since 'C:\inetpub\wwwroot' should be the 'framework project', and build context needs to be the 'solution'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants