nil4 / dotnet-transform-xdt

Modern .NET tools and library for XDT (Xml Document Transformation)
Apache License 2.0
118 stars 12 forks source link

Run with only .NET Core 3.x installed #42

Closed kimbirkelund closed 4 years ago

kimbirkelund commented 4 years ago

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.

nil4 commented 4 years ago

@kimbirkelund thank you for this suggestion! I agree it would be a good feature to have.

I added <RollForward>Major</RollForward> in https://github.com/nil4/dotnet-transform-xdt/commit/78372c6976369c152701e90f8de5b5b206e9d538 and can see that after build, the value is included in dotnet-xdt.runtimeconfig.json:

{
  "runtimeOptions": {
    "tfm": "netcoreapp2.1",
    "rollForward": "Major",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "2.1.0"
    }
  }
}

Would you be up for helping me confirm that this works for you? You can download the artifacts of the build with this change here:

kimbirkelund commented 4 years ago

Cool.

It works as expected 👍

nil4 commented 4 years ago

Thanks for checking! I plan to release a new 2.2.0 version in the next few days.

kimbirkelund commented 4 years ago

No problem. Looking forward to it 👍

nil4 commented 4 years ago

@kimbirkelund the 2.2.0 packages are published to NuGet, but it may take a few hours until they are listed. The tool package (https://www.nuget.org/packages/dotnet-xdt/2.2.0) includes this change.

elangelo commented 3 years ago

I'm still truggling with this. I had this completely working for a .NET core 2.0 project with .NET core 2.0 run time installed. Our IT department is pushing to remove .NET core 2.0 and move to .NET core 3.x. My project is setup like this:

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="2.0.0" />
  </ItemGroup>

  <Target Name="ApplyXdtConfigTransform" BeforeTargets="_CopyAppConfigFile">
    <PropertyGroup>
      <_SourceWebConfig>$(MSBuildThisFileDirectory)app.config</_SourceWebConfig>
      <_XdtTransform>$(MSBuildThisFileDirectory)App.$(Configuration).config</_XdtTransform>
      <_TargetWebConfig>$(IntermediateOutputPath)$(TargetFileName).config</_TargetWebConfig>
    </PropertyGroup>
    <Exec Command="dotnet transform-xdt --xml &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --verbose --output &quot;$(_TargetWebConfig)&quot;" Condition="Exists('$(_XdtTransform)')" />
    <ItemGroup>
      <AppConfigWithTargetPath Remove="App.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>

I've tried upgrading the version to 2.2.0 but that doesn't seem to be available? Help appreciated.

nil4 commented 3 years ago

@elangelo the latest version of the Microsoft.DotNet.Xdt.Tools package is still 2.0.0, published in 2017. That won't work on newer .NET Core runtimes.

The discussion in this issue is about dotnet-xdt, a global (as opposed to project-level) tool which does run with newer .NET Core. See the release details https://github.com/nil4/dotnet-transform-xdt/releases/tag/v2.2.0 and the documentation at https://github.com/nil4/dotnet-transform-xdt#-global-tool-for-net-core-21-and-later--

What you can do for your project is:

  1. Run dotnet tool install -g dotnet-xdt to install the global tool (you only need to do this once)
  2. Verify that you can run dotnet-xdt successfully in your project folder
  3. Remove <DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="2.0.0" /> from your project
  4. Update the tool invocation in your project, from <Exec Command="dotnet transform-xdt [...] to <Exec Command="dotnet-xdt [...]