Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Best way to handle symbols in packages.config. #15

Open
pierceboggan opened this issue Jun 19, 2017 · 2 comments
Open

Best way to handle symbols in packages.config. #15

pierceboggan opened this issue Jun 19, 2017 · 2 comments

Comments

@pierceboggan
Copy link

Problem

I need to be able to optionally add/remove NuGet packages from a project based on a symbol's value. I would love if we had a sample that accomplished this, as I think it's a somewhat-common ask of a templating engine.

Potential Solutions

Outside of having multiple packages.config, what is a sufficient solution? You can't really markup a packages.config with symbols if you want the project to still be able to restore NuGets when opened.

@johanbenschop
Copy link

I just had the same 'problem' and found a good solution. The templating engine has several SpecialOperationConfigs built in, among which is one for **/packages.config using the same syntax as for XML (see https://github.com/dotnet/templating/blob/master/src/Microsoft.TemplateEngine.Orchestrator.RunnableProjects/SimpleConfigModel.cs#L435 for reference).

Inside of your packages.config simply add comments above and below the lines you want to be added (or removed) conditionally as below.

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <!--#if (myCondition)-->
  <package id="System.Optionally.Included" version="42.0.0" targetFramework="net47" />
  <!--#endif-->
</packages>

@sayedihashimi
Copy link
Member

@johanbenschop has the correct approach.

I'd like to close this since I believe that it should be fixed with the comment previously posted. Is there still any issue that needs to be addressed here?

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

No branches or pull requests

3 participants