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

Generating a Dockerfile from VS with CPM enabled omits COPY for package props files #439

Open
oising opened this issue Aug 9, 2024 · 3 comments

Comments

@oising
Copy link

oising commented Aug 9, 2024

When using Central Package Management, the dockerfile generated is missing the required COPY statements for Directory.Build.props (contains the use CPM directive) and Directory.Packages.props. I'm generating the dockerfile with the standard "add new item... / docker support..." menu. I leave the defaults as is: linux, net8, dockerfile etc.

I tried declaring use CPM directly in the csproj but it also fails to add the requisite COPY statements in the dockerfile.

I'm using:

dotnet 8.0
Visual Studio (17.10)
Microsoft.VisualStudio.Azure.Containers.Tools.Targets(1.21.0)
nuget (6.10) -- not sure if this has anything to do with anything

Directory.Build.props:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
</Project>

Adding the following lines to our dockerfile(s) "fixes" the issue:

COPY ["Directory.Build.props", "Directory.Build.props"]
COPY ["Directory.Packages.props", "Directory.Packages.props"]
@oising
Copy link
Author

oising commented Aug 12, 2024

@patverb said:

@oising I was just checking, and it looks like we have do have a bug where if the Directory.Build.props file is in the same directory as the build context and project, we won't add the COPY statement. I'll get a fix out for that in 17.12.

Is that the same layout you have in your project that doesn't work or could you tell me the layout of your project with the locations of the solution, project, docker build context, and Directory.Build.props file please and I'll try to repo it.

The structure is like this:

- /
   - foo.sln
   - Directory.Build.props
   - Directory.Packages.props
   - groupingfolder/
      - projectfolder1/
        - project1.csproj
        - Dockerfile
      - projectfolder2/
        - project2.csproj
        - Dockerfile

yaml template (azure devops)

parameters:
- name: projectName
  type: string
  default: null
- name: imageRepository
  type: string
  default: null

steps:
- task: DownloadPipelineArtifact@2
  displayName: Download Artifact
  inputs:
    buildType: 'current'
    targetPath: '$(Agent.BuildDirectory)'

- task: Docker@2
  displayName: Docker Build&Push Image
  inputs:
    containerRegistry: '<registryname>'
    repository: ${{ parameters.imageRepository}}
    command: 'buildAndPush'
    Dockerfile: '$(Agent.BuildDirectory)/**/${{ parameters.projectName }}/Dockerfile'
    buildContext: './'
    tags: |
      latest
      $(Build.BuildId)

NOTE In Visual Studio 2022 (17.10 & 17.11) I can repro with "add new... docker support" menu item.

@dbreshears dbreshears added the bug label Aug 12, 2024
@patverb
Copy link
Contributor

patverb commented Aug 12, 2024

@oising thank you for getting me that project layout. I fixed a bug we had for looking at files to copy more than 1 directory higher than the project (since yours were in the "groupingfolder") and it should be released in 17.12. Sorry I missed this case initially.

@oising
Copy link
Author

oising commented Aug 12, 2024

Excellent! thank you @patverb for the update. We've hand-modified the Dockerfile(s) to fix the issue by adding:

COPY ["Directory.Build.props", "Directory.Build.props"]
COPY ["Directory.Packages.props", "Directory.Packages.props"]

Putting this here for anyone else who finds this issue.

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

No branches or pull requests

3 participants