Comments (16)
@d668 try and tell us. I'm not the author nor obligated to help you.
from slow-cheetah.
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.
By the moment I am using dotnet-transform-xdt
from slow-cheetah.
@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.
@HansKindberg , thanks for posting.
My xml transformations in asp.net core now works!
from slow-cheetah.
What worked for me:
- Use latest Microsoft.VisualStudio.SlowCheetah 3.2.20 instead of old SlowCheetah 2.5.48
- Set
TransformOnBuild
for app.config:
<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.
Are there any plans on supporting this feature?
from slow-cheetah.
Any update on this?
from slow-cheetah.
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.
Hi @gbergamo
I suppose you want to transform when publishing a .NET Core console application. Is that correct?
from slow-cheetah.
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.
any other solution that doesn't involve 250 lines of gibberish code?
from slow-cheetah.
<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 "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)"" 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 "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)"" 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 "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)"" Condition="Exists('$(_XdtTransform)')" />
</Target>
from slow-cheetah.
@xumix in .NET 4 I could debug any environment config. Is it impossible now?
from slow-cheetah.
Here is a demo https://github.com/d668/NetCoreConfigTransform/ .NET Core 2.2 Console app App.config transforms using slow-cheetah
from slow-cheetah.
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)
- JSON file add transform creates UTF-8-BOM encoding files while source file is UTF-8. This UTF-8-BOM is not supported by most decoders. HOT 1
- Newtonsoft.Json vulnerability to DoS attacks in versions before 13.0.1 HOT 5
- Xml and config transformation does not work on UWP HOT 4
- This repo is missing important files
- Use INuGetProjectService instead of IVsPackageInstallerServices
- SlowCheetah no longer working in VS2019 HOT 1
- Transformation Damages Values with ">" in Them HOT 2
- Problem with readonly app.config files
- ClickOnce not coping data files after Transform
- The transformation is correctly applied and the resulting config file in the output looks as expected. But the configuration loaded in memory is as if taken from the original config file. project is .net framework 4.7.2 self-hosted winform app using appsettings.config file
- How to json arrays of objects or attributes therein HOT 4
- VS2022 Error while loading solution HOT 16
- Transform Not Working In Template Studio Created WinUI 3 Projet
- Old NuGet project page still accessible and getting downloads HOT 1
- TransformXml task could not be loaded from the assembly HOT 1
- SlowCheetah 'File not found' issue when publishing to the file system using msbuild HOT 1
- Per-user transformations HOT 1
- App.config Transform not working with VS2022 HOT 3
- Transform fails when project is targetting multiple frameworks HOT 2
- Publish WPF Core App with ClickOnce does not transform App.Config
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slow-cheetah.