0

I have a class library that has app.config with transformations as app.Dev.config, app.Test.config. This class library is used by a web Api that had web.config transformations as follows: Web.Dev.config, Web.Test.config. When the web api is published in DEV, it correctly uses the web.dev.config, however, for the class library it uses the app.config instead of app.dev.config

I am using ConfigurationTransform from https://marketplace.visualstudio.com/items?itemName=GolanAvraham.ConfigurationTransform

I also tried the solution from: App.Config Transformation for projects which are not Web Projects in Visual Studio?

app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="connectionUri" value="https://ssrsservice-test.azurewebsites.net" />
  </appSettings>
</configuration>

app.Dev.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="connectionUri" value="https://ssrsservice-dev.azurewebsites.net" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
  </appSettings>
</configuration>

After trying the above methods, the connectionUri is always the test one(from app.config) instead of using the dev.

dokyalashot
  • 105
  • 2
  • 18
  • Those transformations are only applied for web projects. For other project types, you need an extension. I think its called Cheetah. Google "visual studio extension cheetah" and you'll find it. –  Apr 11 '19 at 20:50
  • Are you sure that your Web API looks for app.config? If your class library is used within the Web API project, it will look for its settings from the web.config. Now, if you are running unit tests on your class library and those tests have dependencies on the settings (which you should avoid), then the tests would be looking for them in app.config. But, for a Web API using your class library, the web.config is what will be referenced. – RWRkeSBZ Apr 11 '19 at 21:36
  • Here's the link for SlowCheetah transformation tool https://marketplace.visualstudio.com/items?itemName=vscps.SlowCheetah-XMLTransforms – vendettamit Apr 11 '19 at 21:57
  • You can do app Config transforms for an executable without using Slow Cheetah, but I've never seen it done for a class library – pinkfloydx33 Apr 11 '19 at 22:51
  • @RWRkeSBZ the Web Api is looking for it's own web.config with transaformations, however, the class library gets the connection string, url for REST calls information from the app.config. – dokyalashot Apr 12 '19 at 14:11
  • @dokyalashot What you are saying is very unlikely. As far as the class library code is concerned, it is running within an IIS process and will look for its settings in the Web.config. – RWRkeSBZ Apr 12 '19 at 14:14
  • @Amy tried adding transformations using Slow Cheetah, but doesn't seem to help. – dokyalashot Apr 12 '19 at 14:45
  • Right, during execution, the library's config file isn't used. The config of the executing assembly is. –  Apr 12 '19 at 15:30

1 Answers1

0

https://stackoverflow.com/a/50506226/10485667

The solution given in this post helped me to get what I was looking for.

dokyalashot
  • 105
  • 2
  • 18