nil4 / dotnet-transform-xdt

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

Doesn't work for netcoreapp1.1 ? #10

Closed ralphcooper closed 7 years ago

ralphcooper commented 7 years ago

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 packageMicrosoft.DotNet.Xdt.Toolscould not be resolved.

I'm targeting the netcoreapp1.1 framework and using Microsoft.AspNetCore version 1.1.1

nil4 commented 7 years ago

@ralphcooper sorry to hear this, I haven't seen that particular error before, so I would need a bit more information (ideally a simplified repro case) to understand what the issue is. One thing to check up front: are you using the latest XDT tool version 1.2.0, using a reference like this: <DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="1.2.0" />?

I have a repository containing a few XDT samples here: https://github.com/nil4/xdt-samples. I tested these and they work fine with netcoreapp1.0; it may be that something changed in netcoreapp1.1 that I am not yet aware of.

Instead of creating a repro case from scratch, perhaps you could clone the samples repo, then cd WebServerSettingsSample and run dotnet restore and dotnet publish -c Release. If this works fine for you, please edit WebServerSettingsSample.csproj and change <TargetFramework> to netcoreapp1.1; then restore and publish again.

I'll try the same on my end, and it would be helpful if you could let me know how it works for you.

nil4 commented 7 years ago

@ralphcooper I updated the WebServerSettingsSample to netcoreapp1.1 (this line) and ran restore and publish. It worked fine; below is the output. Do you see something different?

> dotnet restore
  Restoring packages for D:\xdt-samples\WebServerSettingsSample\WebServerSettingsSample.csproj...
  Restoring packages for D:\xdt-samples\WebServerSettingsSample\WebServerSettingsSample.csproj...
  Generating MSBuild file D:\xdt-samples\WebServerSettingsSample\obj\WebServerSettingsSample.csproj.nuget.g.props.
  Generating MSBuild file D:\xdt-samples\WebServerSettingsSample\obj\WebServerSettingsSample.csproj.nuget.g.targets.
  Writing lock file to disk. Path: D:\xdt-samples\WebServerSettingsSample\obj\project.assets.json
  Restore completed in 1.02 sec for D:\xdt-samples\WebServerSettingsSample\WebServerSettingsSample.csproj.
  Installing Microsoft.DotNet.Xdt.Tools 1.2.0.
  Restore completed in 3.57 sec for D:\xdt-samples\WebServerSettingsSample\WebServerSettingsSample.csproj.

  NuGet Config files used:
      C:\Users\nil4\AppData\Roaming\NuGet\NuGet.Config
      C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

  Feeds used:
      https://api.nuget.org/v3/index.json

  Installed:
      1 package(s) to D:\xdt-samples\WebServerSettingsSample\WebServerSettingsSample.csproj

> dotnet publish -c Release
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

  WebServerSettingsSample -> D:\xdt-samples\WebServerSettingsSample\bin\Release\netcoreapp1.1\WebServerSettingsSample.dll
  [XDT] Transforming 'D:\xdt-samples\WebServerSettingsSample\Web.config' using 'D:\xdt-samples\WebServerSettingsSample\Web.Release.config' into 'bin\Release\netcoreapp1.1\publish\Web.config'
ralphcooper commented 7 years ago

Thanks for the quick response.

I tried what you suggested and it worked fine with the sample apps publishing to a local folder, which means there must be something wrong with my setup somewhere!

To give a bit more info, I'm publishing via VS 2017 to IIS via MSDeploy (which also seems to work fine for the sample app).

I'll do a closer comparison between the sample app and mine, and let you know what I find.

Thanks again for your help.

nil4 commented 7 years ago

@ralphcooper I'll close the issue for now, as the problem doesn't appear related to code in this repo, but if you do track it down and there is some defect, please reopen with a repro. Thanks!

ralphcooper commented 7 years ago

No defect. I stripped my .csproj back to bare bones and built it up again, then it worked fine.

Sorry - no idea what was wrong the first time, but thanks again for helping out.

LucidObscurity commented 7 years ago

Just a note on something I found. When targeting the .net framework in asp.net core, assembly binding information is added to the [app name].config file in the publish \out directory. If you want to transform your App.config file, you need to use the modified file in the publish directory as the source or else you may get binding errors when running your application.

<Target Name="ApplyXdtConfigTransform" BeforeTargets="_TransformWebConfig">
    <PropertyGroup>
      <_SourceWebConfig>$(PublishDir)$(TargetFileName).config</_SourceWebConfig>
      <_XdtTransform>$(MSBuildThisFileDirectory)App.$(Configuration).config</_XdtTransform>
      <_TargetWebConfig>$(PublishDir)$(TargetFileName).config</_TargetWebConfig>
    </PropertyGroup>
    <Exec Command="dotnet transform-xdt --xml &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot;" Condition="Exists('$(_XdtTransform)')" />
</Target>