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

Xdt Transforms support in Package Reference #5954

Closed
nkolev92 opened this issue Sep 28, 2017 · 12 comments
Closed

Xdt Transforms support in Package Reference #5954

nkolev92 opened this issue Sep 28, 2017 · 12 comments

Comments

@nkolev92
Copy link
Member

XDT Transforms don't work for transitive restore

https://msdn.microsoft.com/en-us/library/dd465326%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
https://blog.nuget.org/20130920/how-to-use-nugets-xdt-feature-examples-and-facts.html)

There are over 700 unique packages on nuget.org that have xml transforms.

This can't be done in PackageReference currently because the concept of install/uninstall is non existent.
Package Reference does not change any project artifacts by design!

These transforms are normally required in the published application, however we need to consider the F5 experience, since just building does not copy over the config files.

Another concern is that not only web.config files are being transformed but also applicationinsights.xmls, UI.xml and seemingly random xmls .

  1. We can maybe do the transform in the build targets of nuget, that way we don't have inconsistent behavior among VS and CLI/EXE.
  2. Work with the web teams to get it done on publish.
@jainaashish
Copy link
Contributor

Made some progress on this to transform via targets, facing one issue with web.config file. Need to follow it with ASPNET team.

@jainaashish
Copy link
Contributor

Added NuGet samples to demonstrate how to author and consume packages with PackageReference which transform xml files using msbuild targets.

PR# NuGet/Samples#15

@jainaashish
Copy link
Contributor

Sample PR is merged to show how can we transform xml files with msbuild targets which will allow it to work with PackageReference

@iskiselev
Copy link

Provided sample solution will not work for ASP.NET Core projects - they do not have TransformWebConfigCore and similar tasks on build, still they may have web.config file to configure IIS module behavior.
Which is worse, they also apply some web.config transforms in _TransformWebConfig target.
So, I believe original issue is not yet fully resolved.

@iskiselev
Copy link

iskiselev commented Dec 20, 2017

Suggested solution also fails when publishing to Microsoft Azure App Service. Just try to create Microsoft Azure App Service publish profile and publish it there with sample consuming project.
It fails with:

2>        ParameterizeTransformXml: Transforming Source File: C:\Samples-master\XDTransformExample\consuming\MyWebApp\obj\Release\TransformWebConfig\transformed\Web.config;obj\Release\TransformWebConfig\transformed\Web.config
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(2311,5): Error : Could not open Source file: Could not find a part of the path 'C:\Samples-master\XDTransformExample\consuming\MyWebApp\obj\Release\TransformWebConfig\transformed\Web.config;obj\Release\TransformWebConfig\transformed\Web.config'.

Suggested solution also prevents from applying VS standard Web.Debug.config/Web.Release.config transforms when publishing to folder selected.
It will be skipped, thanks to up-to-date check:

2>    Target "TransformWebConfigCore" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets" from project "C:\projects\nuget\SiteSamples\OldConfig\OldConfig.csproj" (target "TransformWebConfig" depends on it):
2>        Skipping target "TransformWebConfigCore" because all output files are up-to-date with respect to the input files.
2>        Input files: Web.config;C:\projects\nuget\SiteSamples\OldConfig\Web.Release.config
2>        Output files: obj\Release\TransformWebConfig\transformed\Web.config
2>        Done building target "TransformWebConfigCore" in project "OldConfig.csproj".

Definitely, we try to apply transform to same file twice with Inputs="@(WebConfigsToTransform);%(TransformFile)" Outputs="$(_WebConfigTransformOutput)". For first time, TransformWebConfigCore target will be called, but for second it will be already up-to-date.

@jainaashish
Copy link
Contributor

@iskiselev Thanks for letting us know these issues. We'll analyze these issues.

@jainaashish jainaashish reopened this Dec 20, 2017
@jainaashish
Copy link
Contributor

Update:

Provided sample solution will not work for ASP.NET Core projects
This is expected since msbuild targets for ASP.NET core vs classic projects are totally different. ASP.NET team has a work item to add web.config transform support for core projects.

Suggested solution also fails when publishing to Microsoft Azure App Service
This is a bug in ASP.NET target with 'AutoParameterizationWebConfigConnectionStrings' to handle custom transforms. We can workaround it for now by setting it to false in csproj file until ASP team fixes it.

@jainaashish
Copy link
Contributor

Let us know if you see any other issue!

@iskiselev
Copy link

What about preventing from applying VS standard Web.Debug.config/Web.Release.config?

@jainaashish
Copy link
Contributor

That has nothing to do with NuGet and is out of scope for this issue. You can check with ASP.NET team.

@johnson512n28
Copy link

johnson512n28 commented Jan 25, 2019

@jainaashish Is this Xdt Transform sample currently working? Getting the master branch, I assumed that installing the package into the MyWebApp and doing a build would transform the config files, but it doesn't. Any tips?

@ryno1234
Copy link

ryno1234 commented Apr 19, 2019

@jainaashish, I cannot seem to adapt this sample to work for our project. A few questions before I spend any more time debugging the issue:

  • Is this meant to work when the target project is an SDK-style project using the new csproj format?
  • Is the transform supposed to occur during installation of the Nuget package, during build of the consuming project or during publish of the consuming project?

This issue was closed.
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

7 participants