Closed nkolev92 closed 6 years ago
Made some progress on this to transform via targets, facing one issue with web.config file. Need to follow it with ASPNET team.
Added NuGet samples to demonstrate how to author and consume packages with PackageReference
which transform xml files using msbuild targets.
Sample PR is merged to show how can we transform xml files with msbuild targets which will allow it to work with PackageReference
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.
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.
@iskiselev Thanks for letting us know these issues. We'll analyze these issues.
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.
Let us know if you see any other issue!
What about preventing from applying VS standard Web.Debug.config/Web.Release.config?
That has nothing to do with NuGet and is out of scope for this issue. You can check with ASP.NET team.
@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?
@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:
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.