Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

C# Transformation of App.config with SlowCheetah on build doesn't work

update added The question is - what I'm missing?

I need to transform app.config on building. I've set up Microsoft.VisualStudio.SlowCheetah. I made all as described at https://www.hanselman.com/blog/slowcheetah-webconfig-transformation-syntax-now-generalized-for-any-xml-configuration-file Preview transform works good, but when I build - it puts just trasformation file to the output folder, not trasformed app.config.

VS 2019 Community, .NET Framework 4.5, Windows desktop application. I made build configurations, such as Inst1_Debug, Inst2_Release and so on, several. I have batch build. I made some manual changes to csproj file:

  <PropertyGroup>
...
    <AppConfig>App.$(Configuration).config</AppConfig>
</PropertyGroup>

  <ItemGroup>
    <Content Include="App.config">
      <TransformOnBuild>true</TransformOnBuild>
    </Content>
    <Content Include="App.Inst1_Debug.config">
      <TransformOnBuild>true</TransformOnBuild>
      <DependentUpon>App.config</DependentUpon>
      <IsTransformFile>true</IsTransformFile>
    </Content>
...

and this was added by SlowCheetah:

 <Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />
  <Import Project="packagesMicrosoft.VisualStudio.SlowCheetah.3.2.26uildMicrosoft.VisualStudio.SlowCheetah.targets" Condition="Exists('packagesMicrosoft.VisualStudio.SlowCheetah.3.2.26uildMicrosoft.VisualStudio.SlowCheetah.targets')" />

When I build with batch build, or just rebuild with particular build configuration, I get just transformation file as MyExe.exe.config file, while Prewiew Transfom looks good.

Update: I made Clean and then Rebuild, now transformation seems to work, but in output I see only those parameters that I changed in transformation. Source config is absent. To check "no transformation" case I added default transformation with right-click "Add Transfrom" on App.Config, App.Degub.config:

<?xml version="1.0" encoding="utf-8"?>
<!--For more information on using transformations see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
</configuration>

App.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
  <appSettings>
    <add key="FilePath" value="E:FOLDER1" />
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

When I build, I get MyApp.exe.config in output:

<?xml version="1.0" encoding="utf-8"?>
<!--For more information on using transformations see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
</configuration>

But I expect unchanged content of App.config, as no transformation added. Preview transform looks good, as expected.

In csproj:

<Content Include="App.config">
  <TransformOnBuild>true</TransformOnBuild>
</Content>
<Content Include="App.Debug.config">
  <DependentUpon>App.config</DependentUpon>
  <IsTransformFile>true</IsTransformFile>
</Content>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...