I have a solution with these three projects.
The DAL project is a class library that has a web reference. Thus, the app.config in that project has a section like this:
<applicationSettings>
<Company.Project.Domain.Properties.Settings>
<setting name="Company_Project_Domain_Some_Service" serializeAs="String">
<value>http://my.server.local:8888/somePath/service.asmx</value>
</setting>
</Company.Project.Domain.Properties.Settings>
</applicationSettings>
I have slow cheetah installed and am using config transforms in this DAL project. For example, I have a app.production.config that transforms the above web reference to point to the production web reference like so:
<applicationSettings>
<Company.Project.Domain.Properties.Settings>
<setting name="Company_Project_Domain_Some_Service" serializeAs="String">
<value>http://my.PRODUCTIONSERVER.local:8888/somePath/service.asmx</value>
</setting>
</Company.Project.Domain.Properties.Settings>
</applicationSettings>
When I publish the API, the web.config doesn't contain ANY application setting shown above. I can use reflector to drill into the DAL.dll and see the service.asmx path. However, it doesn't do the transform so the published app does NOT use the my.PRODUCTIONSERVER.local:8888.
Thus two questions.
Firstly adding web references into a library does not seem like a good idea. Because libraries are reusable pieces of code that are self contained and can be used across different projects. Based on that logic I'm curious to know why you chose to separate out DAL into a project instead of another folder inside the web API. But I'll leave that discussion for later.
To answer your first question,
Why does publishing NOT use the xdt transform in the referenced class library?
Publishing only transforms configs inside the web app from which you are publishing. I'm not sure how you are publishing you app but if you used command line you'd probably do something like this.
msbuild /p:PublishOnBuild WebApi.csproj
MsBuild uses your .csproj file to build and publish your app. And within the .csproj contains the information needed for transformation. Hence MsBuild does NOT know that it needs to transform app.config from the referenced library which is why your config from DAL is not transformed but just copied.
Moving on to your second question
If the application settings block MUST be in the web.config of the Web API project, does that mean I should remove the web reference from the DAL and add it to the Web API project? ...or can I just leave the reference alone and copy the relevant applicationSettings block to the web.config?
You have a few options here,