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

Keep ItemGroup Condition when switching projects <-> packages #127

Open
Leon99 opened this issue Jan 10, 2023 · 1 comment
Open

Keep ItemGroup Condition when switching projects <-> packages #127

Leon99 opened this issue Jan 10, 2023 · 1 comment

Comments

@Leon99
Copy link

Leon99 commented Jan 10, 2023

Currently, switching between projects and packages may cause unexpected changes due to moving the PackageReference/ProjectReference to an ItemGroup without a Condition.

A typical approach when multitargeting is to have something like this:

...
  <ItemGroup Condition="'$(TargetFramework.StartsWith(`net4`))'">
    <PackageReference Include="NetFrameworkOnlyPackage" Version="*" />
...

Using dnt to switch that package will result in referencing it unconditionally.

Is there a way to keep the replaced reference with the same ItemGroup on switching?

@ssteiner
Copy link

I think the MSBuild APis don't allow that. I'm looking at the source for another matter, but the API used AddItem doesn't seem to allow selecting the ItemGroup, let alone creating an ItemGroup with conditions. But I've just started playign around with it. If you care to have a look yourself, look at SwitchProjectsToPackagesCommand and SwitchPackagesToProjectsCommand - the code is reasonably easy to understand.

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