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

How to fix the issues with TargetFrameworks? #315

Open
lucapivato opened this issue Nov 10, 2021 · 3 comments
Open

How to fix the issues with TargetFrameworks? #315

lucapivato opened this issue Nov 10, 2021 · 3 comments

Comments

@lucapivato
Copy link

Checked everywhere I could search but didn't find any meaningful information. Any help is highly appreciated. I feel it should be fairly simple unless there is a bug in the docker tools.

I have projects with multiple targets, like this:

<TargetFrameworks>net5.0;net6.0</TargetFrameworks>

or

<TargetFrameworks>net48;net6.0</TargetFrameworks>

or

<TargetFrameworks>net48;net5.0;net6.0</TargetFrameworks>

Problems:

Docker tools for Visual Studio seem to get confused:

  • If net48 is first, it assumes that I'm targeting Windows even with  <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
  • if net5.0 is first it always runs 5.0 but if the dockerfile uses FROM ... 6.0 so the 6.0 image obviously doesn't work with a 5.0 build.

I cannot find any way to set 1) the target OS and/or 2) the target framework. Something as simple as setting the OS to Linux and the TargetFramework to "net6.0" when <TargetFrameworks> is set either "net48;net5.0;net6.0" or "net5.0;net6.0".

Tried:

  • DockerDefaultTargetOS (ignored)
  • DockerTargetFramework (ignored and it can only be "DotNetCore" or "DotNetFramework" anyway)

Thanks.

@ravipal
Copy link
Contributor

ravipal commented Nov 15, 2021

Docker tooling doesn't support adding docker support on projects with TargetFramwroks. Looks like you added the TargetFrameworks after adding docker support. Having said that it could still work as long as you have the TargetFrameworkIdentifier (which is derived from the TargetFramwroks), DockerDefaultTargetOS and the base image defined in the dockerfile all compatible. For example, you can't use net48 (.NETFramework) on Linux OS.

@lucapivato
Copy link
Author

Thank you for your answer.

Tried:

   <TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
  <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
 

Doesn't seem to make a difference:

  • Always asks if I want to switch to Windows
  • Always fires a CTC1015 Docker command failed because "the source path ..." too many colons.

Removing net48 from the target frameworks removes the OS switch message box (basically DockerDefaultTargetOS seems not to be used).

But keeping net5.0;net6.0 still fails for net6.0.

So I guess the final answer is that docker tooling doesn't support multiple targets?

@ravipal
Copy link
Contributor

ravipal commented Nov 16, 2021

One of the .Net targets sets the TargetFrameworkIdentifier based on the TargetFramework and TargetFrameworks, so this value shouldn't be set in the project. The Container.targets from microsoft.visualstudio.azure.containers.tools.targets nuget package overrides the DockerDefaultTargetOS to Windows if the TargetFrameworkIdentifier is .NETFramework irrespective of what is defined in the project file. So having a TargetFrameworks with mix of .NETCore and .NETFrameworks will results into different docker os and one of the docker build is going to fail. Initially I thought having a right set of matching DockerTargetOS, base image and targetframework would work, but it didn't.

Having a compose project targeting multiple frameworks is not a supported scenario.

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