-2

I'm working with Visual Studio 2017. I've inherited a web project and am trying to introduce build configurations for the config transforms. What I am finding odd is that no matter what build configuration I select, the project always compiles to the bin\ directory, no subdirectory for the build selected.

What's further strange is that I created two new web projects to discover where the problem might be and got different results. One was a .Net Core web project, which did create the Debug and Release directories when compiled under those build configurations. The other, like the inherited project, was a .Net Framework web project, and it also would only compile to the bin\ directory.

Does anyone have any idea what is going on?

Random
  • 1,896
  • 3
  • 21
  • 33
  • Have you checked the output path in project properties -> Build? You can select configuration from drop down – itdoesntwork Sep 11 '18 at 15:37
  • What are you doing when you're "trying to introduce build configurations"? – Ian Sep 11 '18 at 15:38
  • Use MSBuild logging switches, to check detailed or diagnostics output, and the output directory selection would be clear to you, as all calculation would be printed out. – Lex Li Sep 11 '18 at 16:00
  • @itdoesntwork, yes, I have checked the output path. It is set to bin\, however it was my thought this was just the "root", with the build appended to that. On a lark, I put in "Debug" on the end, and it compiled the project dll to that directory, but did not copy the config or the references over. I think there is still something missing. – Random Sep 11 '18 at 16:13
  • @Ian, I'm trying to get different builds to build in their own respective directories, performing transforms on the config, and automatically copying over referenced dlls. – Random Sep 11 '18 at 16:16
  • @Lex-Li, I'm unsure how logging switches would help. I can see in the output pane that the build happens exactly where I find it. – Random Sep 11 '18 at 16:17
  • Diagnostics logging of MSBuild reveals all details you need to fully understand how the project file (and all its configuration) is transformed to build time behaviors (much more than step by step manner). The Output pane in VS might not show you much (unless you check VS settings to let it show diagnostics output as well). It is OK that you are "unsure", but once try it you should immediately know why I suggested that. – Lex Li Sep 11 '18 at 16:23
  • @Lex-Li, just fyi - I did the build to see the details. It did not reveal anything that helped. – Random Sep 12 '18 at 22:35

1 Answers1

0

While I did not discover why the configuration name was not being automatically appended to the output path during the build, nor why transforms were not being applied to the config files, I fixed the problem by hacking the project file.

For each PropertyGroup node that identified the settings to use for the build, I changed the OutputPath value from bin\ to bin\$(Configuration).

Then, I insert the following into the Project node to get the transforms to work:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="AfterCompile" Condition="Exists('Web.$(Configuration).config')">
    <TransformXml Source="Web.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="Web.$(Configuration).config" />
    <ItemGroup>
      <AppConfigWithTargetPath Remove="Web.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>
Random
  • 1,896
  • 3
  • 21
  • 33