nil4 / dotnet-transform-xdt Goto Github PK
View Code? Open in Web Editor NEWModern .NET tools and library for XDT (Xml Document Transformation)
License: Apache License 2.0
Modern .NET tools and library for XDT (Xml Document Transformation)
License: Apache License 2.0
Reference: aspnet/IISIntegration#409 (comment)
This tool works fine on web apps using .net core 2.0 with mvc 6 but with .net 4.6.1 with mvc 6 fails.
Thanks
Hello, there is outdated instruction in section "Project-level dotnet-transform-xdt tool" run dotnet new -t web
.
Command line switch -t in not working any more, is replaced by run dotnet new web
https://stackoverflow.com/a/42807347/245460
Also noted that run dotnet new web
does not create web.config
any more, so you should add web.config to project manually.
I've been using this tool for a while now with no issues. But out of the blue it has started adding duplicate <rule>
nodes to the <rewrite><rules>
section. I haven't even updated the xdt package version.
My web.config in the project looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44350" />
</environmentVariables>
</aspNetCore>
<rewrite>
<rules></rules>
</rewrite>
</system.webServer>
</configuration>
And my web.Staging.config in the project looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<aspNetCore>
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT"
value="Staging"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
</environmentVariables>
</aspNetCore>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect -- Staging"
stopProcessing="true"
xdt:Transform="Insert">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}"
pattern="off"
ignoreCase="true" />
</conditions>
<action type="Redirect"
redirectType="Permanent"
url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
And the deployed web.config that get published to our staging server via AzDevOps pipeline looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyCompany.MyProject.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Staging" />
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44350" />
</environmentVariables>
</aspNetCore>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect -- Staging" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true"/>
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
<rule name="HTTP to HTTPS redirect -- Staging" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true"/>
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<!--ProjectGuid: 546334BB-0661-42B6-844E-31DC3677C6C1-->
The MyCompany.MyProject.csproj file has this:
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="2.0.0" />
</ItemGroup>
<Target Name="ApplyXdtConfigTransform" BeforeTargets="_TransformWebConfig">
<PropertyGroup>
<_SourceWebConfig>$(MSBuildThisFileDirectory)Web.config</_SourceWebConfig>
<_XdtTransform>$(MSBuildThisFileDirectory)Web.$(Configuration).config</_XdtTransform>
<_TargetWebConfig>$(PublishDir)Web.config</_TargetWebConfig>
</PropertyGroup>
<Exec Command="dotnet transform-xdt --xml "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)"" Condition="Exists('$(_XdtTransform)')" />
</Target>
Is there anything that stands out about this setup?
My solution file (.sln) and project file (.csproj) is in the same folder location. If I simply run dotnet transform-xdt
I get:
Specify which project file to use because this 'D:\Projects\Foo' contains more than one project file.
Expected behavior
To specify the project file using normal syntax dotnet transform-xdt .\Foo.csproj
which would result in normal operation.
Observed behavior
It still displays the same error message regardless of specifying the project or solution file.
Additional
This same problem persists when attempting to run the transform as part of the publish step. e.g.
dotnet publish .\Foo.csproj -c production -o D:\webpublish\foo\
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Foo -> D:\Projects\Foo\bin\production\netcoreapp1.1\Web.dll
Foo -> D:\webpublish\foo\
Specify which project file to use because this 'D:\Projects\Foo' contains more than one project file.
D:\Projects\Foo\Foo.csproj(80,5): error MSB3073: The command "dotnet transform-xdt --xml "D:\Projects\Foo\Web.config" --transform "D:\Projects\Foo\Web.production.config" --output "D:\webpublish\Foo\Web.config"" exited with code 1.
v2.2.0
According to the help there is a quiet option that will only print error messages. However, it is not recognized as an option.
Options:
--help|-h|-? Print usage information
--quiet|-q Print only error messages
--verbose|-v Print verbose messages while transforming
dotnet-xdt.exe --source "source.config" --transform "transform.config" --output "output.config" --quiet
[dotnet-xdt] Invalid argument: '--quiet'
dotnet-xdt.exe -s source.config -t transform.config -o output.config -q
[dotnet-xdt] Invalid argument: '-q'
Port unit tests from CodePlex when NetStandard 2.0 and NETCoreApp1.2 are released, to ensure #4 is fixed and stays fixed.
Not needed if the official port effort starts as per aspnet/Tooling#780.
Should I use the Project-level configuration? I'm on dotnet 2.1.1.
Hi,
I'm using Microsoft.DotNet.Xdt.Tools version 2.0.0 .Net Core 2.0 and added the following command to run after publish but it hangs intermittently.
dotnet transform-xdt -x web.config -t web.$(ConfigurationName).config -o $(PublishDir)web.config
I test the command as below when I encounter publish is hanging and it hangs the same way.
dotnet transform-xdt -x web.config -t web.Staging.config -o web.test.config
I wasn't able to see it returning an error message to help investigating the issue further, don't know if the tool stores logs either. Problem disappears as it appeared after a period of time that I'm not sure if it's a fixed amount.
Can I prevent the hangs or find out the reason?
Currently, whitespace is not correctly preserved when applying transforms; see https://github.com/dotnet/corefx/issues/11196.
When NetStandard 2.0 or NETCoreApp 1.2 is released, it should be easier to revert the code to be closer to the CodePlex original. At that time, investigate why whitespace is not preserved.
Related: dotnet/corefx#12017, https://github.com/dotnet/corefx/issues/11888,
Hi
Since adding the dotnet 2.2 SDK, I am unable to run the dotnet transform-xdt commands. All that I am getting is
Version for package Microsoft.Dotnet.Xdt.Tools
could not be resolved.
I do have the following:
<ItemGroup> <DotNetCliToolReference Include="Microsoft.Dotnet.Xdt.Tools" Version="2.0.0" /> </ItemGroup>
And have the following as a build requirement:
<PropertyGroup>
<_SourceConfig>$(MSBuildThisFileDirectory)nlogbase.config</_SourceConfig>
<_XdtTransform>$(MSBuildThisFileDirectory)nlogbase.$(Configuration).config</_XdtTransform>
<_TargetConfig>$(TargetDir)nlog.config</_TargetConfig>
</PropertyGroup>
<Exec Command="dotnet transform-xdt --verbose --xml "$(_SourceConfig)" --transform "$(_XdtTransform)" --output "$(_TargetConfig)"" />
</Target>
It works 100% when I uninstall 2.2 SDK
Apart from the web.*.config that has to be transformed, we create nlog.config files per environment using the transformation tool.
Any corrective measures that can be done?
Let's say I have a App.config with this section:
<setting name="InstanceName" serializeAs="String">
<value>[[InstanceName]]</value>
</setting>
And a App.Debug.Config with this section:
<setting name="InstanceName" serializeAs="String" xdt:Transform="Replace" xdt:Locator="Match(name)">
<value>Debug</value>
</setting>
After dotnet-transform-xdt does it work, the resulting file will become:
<setting name="InstanceName" serializeAs="String"><value>Debug</value></setting>
At first glance this shouldn't be a problem because it's still a valid XML file, but somehow on execution the .NET System.Configuration class don't like this, and throw a "System.Configuration.ConfigurationErrorsException" exception:
System.Configuration.ConfigurationErrorsException: Unrecognized element 'setting'. (Project\bin\Debug\net5.0\ProjectName.exe.config line 28)
A quick Google search lead me to this and this which are VERY old posts, but it still seems to be the case. I tried with project targeting net472 AND net5.0 and it throw the same error.
When a user specifies a non-existent output folder, the transformation process failed with the following error:
> dotnet xdt --source "locationOriginalFile" --transform "locationDeltaFile" --output "inexistentLocationOutputFile"
[dotnet-xdt] Transforming 'locationOriginalFile' using 'locationDeltaFile' into 'inexistentLocationOutputFile'
[dotnet-xdt] Unexpected error: System.IO.DirectoryNotFoundException: Could not find a part of the path 'inexistentLocationOutputFile'.
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at DotNet.Xdt.Program.Main(String[] args) in d:\a\1\s\dotnet-xdt\Program.cs:line 62
The process should create the non-existent folder, so the transformation would succeed.
Thanks for all the work on this project!
I was attempting to use the project level Microsoft.DotNet.Xdt.Tools
tool in my project and noticed it still seems to have the issue whitespace preservation issues described in #4.
The two other nuget packages appear to have been published more recently. Is the recommendation to use the global tool over the project level tool?
Thank for your project!
This config works for me:
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="2.0.0" />
</ItemGroup>
<Target Name="ApplyXdtConfigTransform" BeforeTargets="_CopyAppConfigFile">
<PropertyGroup>
<_SourceWebConfig>@(AppConfigWithTargetPath)</_SourceWebConfig>
<_XdtTransform>$(MSBuildThisFileDirectory)App.$(Configuration).config</_XdtTransform>
<_TargetWebConfig>@(AppConfigWithTargetPath)</_TargetWebConfig>
</PropertyGroup>
<Exec
Command="dotnet transform-xdt --xml "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)""
Condition="Exists('$(_XdtTransform)')" />
</Target>
Instead of configuration name
1.the target file
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="test20180523" value="1" />
</appSettings>
</configuration>
2.the transform file
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" xdt:Transform="RemoveAttributes(xmlns)" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" />
when I try to apply the transform to the target,nothing happened.
I'm running dotnet version 1.0.0-rc4-004771
Using
<Target Name="ApplyXdtConfigTransform" BeforeTargets="_WebConfigTransform">
<PropertyGroup>
<_SourceWebConfig>$(MSBuildThisFileDirectory)Web.config</_SourceWebConfig>
<_XdtTransform>$(MSBuildThisFileDirectory)Web.$(Configuration).config</_XdtTransform>
<_TargetWebConfig>$(PublishDir)Web.config</_TargetWebConfig>
</PropertyGroup>
<Exec Command="dotnet transform-xdt --xml "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)"" />
</Target>
Transformations do not run on publish.
Trying to sub BeforeTargets="_WebConfigTransform" for AfterTargets="Build" and running dotnet build does not seem to actually do anything. I've tried doing the recommended process also on the sample projects and they do not work either.
I could be doing something wrong I admit, but after following the instructions and updating my csproj file, I get the following error in the output on publish:
Version for package
Microsoft.DotNet.Xdt.Tools could not be resolved.
I'm targeting the netcoreapp1.1 framework and using Microsoft.AspNetCore version 1.1.1
I suggest creating an installer (with framework 462 for an exe) instead of a nuget package.
Two reasons:
It seems to work ok without "
paths and with a _TargetWebConfig
aimed at the $(PublishDir)
, which seems like it would simplify samples a bit (unless it's gonna ๐ฅ otherwise).
<Target Name="RemoveHandlersFromWebConfig" AfterTargets="_WebConfigTransform">
<PropertyGroup>
<_SourceWebConfig>$(PublishDir)web.config</_SourceWebConfig>
<_XdtTransform>$(MSBuildThisFileDirectory)web.RemoveHandlers.config</_XdtTransform>
<_TargetWebConfig>$(PublishDir)web.config</_TargetWebConfig>
</PropertyGroup>
<Exec Command="dotnet transform-xdt --xml $(_SourceWebConfig) --transform $(_XdtTransform) --output $(_TargetWebConfig)" Condition="Exists('$(_XdtTransform)')" />
</Target>
... you may want the capitalized "W" tho in web.config
. I keep mine lowercase, but I am aware of the tradition of using Web.config
in projects out there. [Kind'a strange sometimes which conventions the .NET Core team kept and which ones they changed, since IIS.net is full of upper-case "W" Web.config
mentions.]
[EDIT] Is the "
path thing to cover spaces in paths?
Due to dotnet/sdk#472, the dotnet-transform-xdt.runtimeconfig.json
file is not included in the nupkg file when dotnet pack
runs.
Remove the current hack when the issue is fixed.
I get
Severity Code Description Project File Line Suppression State
Error The command "dotnet transform-xdt --xml "C:\Users\Kevin\Projects\PocketNurse\PocketNurse\Web.config" --transform "C:\Users\Kevin\Projects\PocketNurse\PocketNurse\Web.Omnicell.config" --output "C:\Users\Kevin\Projects\PocketNurse\PocketNurse\obj\Omnicell\netcoreapp2.0\PubTmp\Out\Web.config"" exited with code 1. PocketNurse C:\Users\Kevin\Projects\PocketNurse\PocketNurse\PocketNurse.csproj 34
from this project
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<UserSecretsId>aspnet-PocketNurse-36604171-3424-4347-80E3-30D24138EC43</UserSecretsId>
<Configurations>Debug;Release;Omnicell;Docker</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPPlus" Version="4.5.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.1" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\UploadViewModel\" />
</ItemGroup>
<Target Name="ApplyXdtConfigTransform" BeforeTargets="_TransformWebConfig">
<PropertyGroup>
<_SourceWebConfig>$(MSBuildThisFileDirectory)Web.config</_SourceWebConfig>
<_XdtTransform>$(MSBuildThisFileDirectory)Web.$(Configuration).config</_XdtTransform>
<_TargetWebConfig>$(PublishDir)Web.config</_TargetWebConfig>
</PropertyGroup>
<Exec
Command="dotnet transform-xdt --xml "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)""
Condition="Exists('$(_XdtTransform)')" />
</Target>
</Project>
Adding --verbose I get something like
[XDT] Failed: 'xdt' is an undeclared prefix. Line 18, position 29.
Hi,
I have tested this in a new solution and it works fine. Thanks and great job. However when i tried to incorporate this in my actual solution i am getting error "Specify which project file to use because this c:\pathtofolder\project contains more than one project file."
I looked in the source folder and i have
project.csproj
project.csproj.user
project.csproj.vspscc
This appears to be a known issue with CLI Tools
Is there a way to get around this without deleting other files ?
I have a ASP.NET Core 1.1 MVC project targeting net452 and I'm trying to use Microsoft.DotNet.Xdt.Tools with it. I've tried to install it using Nuget but I'm getting this error. Is it not usable in this .NET Core version?
Package 'Microsoft.DotNet.Xdt.Tools 1.2.0' has a package type 'DotnetCliTool' that is not supported by project 'MyProject'.
csproj:
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<PreserveCompilationContext>true</PreserveCompilationContext>
<OutputType>Exe</OutputType>
</PropertyGroup>
We could not get this working, probably because our project targets the net46 framework.
Would you consider adding support for this use case, or suggest a work-around?
Thanks.
Now that .NET Core 3.1 is out it would be nice if the tool could be run without requiring .NET Core 2.x to be installed.
With 3.0 a new project property RollForward
was introduced, and setting it to Major
allows running to tool on a newer major version than what it was built for. See here for more details.
In dotnet/sdk#462 (comment) @guardrex reports:
I tried running it on <_SourceWebConfig>$(PublishDir)web.config</_SourceWebConfig>, but it looks like a file lock prevents it from overwriting the file in published output.
Unfortunately this can only run with the SDK installed. I want to run this standalone on a server with just the runtime available.
Would you accept a PR to
Also add some TargetFrameworks and pack the stuff for .NET Core 2.0 and 2.1 in the same package.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.