Coder Social home page Coder Social logo

Comments (16)

xumix avatar xumix commented on June 18, 2024 6

@d668 try and tell us. I'm not the author nor obligated to help you.

from slow-cheetah.

HansKindberg avatar HansKindberg commented on June 18, 2024 4

I have temporary solved it by adding the following target to the project-file. Helped by @andresmoschini comment:
https://gist.githubusercontent.com/HansKindberg/7ec0d4779f810675cc51dd5398669726/raw/cfea987bfc9807190ea9c2e4a36dbb40ce1b6be4/ASP.NET-Core-SlowCheetah-temporary-publish-fix.targets

from slow-cheetah.

andresmoschini avatar andresmoschini commented on June 18, 2024 3

By the moment I am using dotnet-transform-xdt

from slow-cheetah.

Bjego avatar Bjego commented on June 18, 2024 2

@tkirill Hey your hint importing SlowCheetah at the end of the csproj file works for me.
I didn't need this fix for some of my projects, but one special .net core service publishing just the subpath got fixed by this:

File to transform:
nlog.config

Building:
TFS 2017 - running 4 cmd commands :

  • dotnet restore
  • dotnet build -c Release
  • dotnet test -c Release -l trx
  • dotnet publish .\src\ServiceName\ServiceName.csproj -c Release -o $(build.artifactstagingdirectory)

Package version:

<PackageReference Include="Microsoft.VisualStudio.SlowCheetah" Version="3.2.26">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

Extended CSProj:

 <Import Project="$(RestorePackagesPath)microsoft.visualstudio.slowcheetah\3.2.26\build\Microsoft.VisualStudio.SlowCheetah.targets"
          Condition="Exists('$(RestorePackagesPath)microsoft.visualstudio.slowcheetah\3.2.26\build\Microsoft.VisualStudio.SlowCheetah.targets')" />

This referrs to:
https://github.com/NLog/NLog/wiki/WebService-target---Workaround-for-url-variables

from slow-cheetah.

PedroNunoSantos avatar PedroNunoSantos commented on June 18, 2024 1

@HansKindberg , thanks for posting.
My xml transformations in asp.net core now works!

from slow-cheetah.

tkirill avatar tkirill commented on June 18, 2024 1

What worked for me:

<ItemGroup>
  <None Include="app.config">
    <TransformOnBuild>true</TransformOnBuild>
  </None>
</ItemGroup>
  • Import SlowCheetah at the end of csproj:
  <Import Project="$(RestorePackagesPath)microsoft.visualstudio.slowcheetah\3.2.20\build\Microsoft.VisualStudio.SlowCheetah.targets"
          Condition="Exists('$(RestorePackagesPath)microsoft.visualstudio.slowcheetah\3.2.20\build\Microsoft.VisualStudio.SlowCheetah.targets')" />

Could someone verify is this workaround is safe?

BTW if you can't upgrade SlowCheetah for some reason it is possible to make old SlowCheetah 2.5 work too. It requires editing its .targets file in build folder in package:

<!-- insert this line -->
<__SC_IntermediateAppConfig>$(IntermediateOutputPath)$(MSBuildProjectFile)-sc.App.config</__SC_IntermediateAppConfig>
<!-- before this line -->
<_Sc_HasAppConfigTransform>false</_Sc_HasAppConfigTransform>

Another option is to use simple transform task which works only for App.config from this discussion. It was reviewed by MSBuild maintainer @rainersigwald so it should work good.

from slow-cheetah.

xumix avatar xumix commented on June 18, 2024

Are there any plans on supporting this feature?

from slow-cheetah.

wouterroos avatar wouterroos commented on June 18, 2024

Any update on this?

from slow-cheetah.

gbergamo avatar gbergamo commented on June 18, 2024

Hey @HansKindberg thanks for your Target property... Just a question, you are using it for Web.Config and AppSettings.json, right? Do you have any idea how I can do it for AppSettings.json and App.Config? Thanks

from slow-cheetah.

HansKindberg avatar HansKindberg commented on June 18, 2024

Hi @gbergamo

I suppose you want to transform when publishing a .NET Core console application. Is that correct?

from slow-cheetah.

d668 avatar d668 commented on June 18, 2024

In .Net 4 you could debug and build for an environment. I am a bit confused what is the proper way for .Net Core. The link that everyone is posting is about ASP, not console app

from slow-cheetah.

d668 avatar d668 commented on June 18, 2024

any other solution that doesn't involve 250 lines of gibberish code?

from slow-cheetah.

xumix avatar xumix commented on June 18, 2024

@d668

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

<!-- For web projects -->
<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 &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot;" Condition="Exists('$(_XdtTransform)')" />
  </Target>

<!-- For console projects -->
<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 &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot;" Condition="Exists('$(_XdtTransform)')" />
  </Target>

<!-- For other files  -->
<Target Name="ApplyXdtConfigTransform2" AfterTargets="_CopyOutOfDateSourceItemsToOutputDirectory">
    <PropertyGroup>
      <_SourceWebConfig>$(OutDir)Nlog.config</_SourceWebConfig>
      <_XdtTransform>$(MSBuildThisFileDirectory)Nlog.$(Configuration).config</_XdtTransform>
      <_TargetWebConfig>$(OutDir)Nlog.config</_TargetWebConfig>
    </PropertyGroup>
    <Exec Command="dotnet transform-xdt --xml &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot;" Condition="Exists('$(_XdtTransform)')" />
  </Target>

from slow-cheetah.

d668 avatar d668 commented on June 18, 2024

@xumix in .NET 4 I could debug any environment config. Is it impossible now?

from slow-cheetah.

d668 avatar d668 commented on June 18, 2024

Here is a demo https://github.com/d668/NetCoreConfigTransform/ .NET Core 2.2 Console app App.config transforms using slow-cheetah

from slow-cheetah.

codystott avatar codystott commented on June 18, 2024

I got it working by adding a new Project Build Configuration (i.e. "MYHOST1") to the project I want to publish, then adding a new Solution Configuration (same name, "MYHOST1") which uses the new Project Build Configuration for that project, then on the Publish Profile specifying "MYHOST1" as the Configuration.

Not very clean, but seems to work. (.NET Core 2.1 console app; SlowCheetah 3.2.20)

from slow-cheetah.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.