skip to Main Content

We have asp.net web project which we are migrating to .NET SDK-style project with centralized nuget package management.

Template that we are using is <Project Sdk="MSBuild.SDK.SystemWeb/4.0.88"> and we have a Web.Config file with three transformations (Debug, Release, Test). Build Action is set to content, and Copy to Output Directory is set to None.

VS build works just fine, however when we try our release build, we get following message:

PreTransformWebConfig:
  Found The following for Config tranformation:
  Web.config, Web.config
  Skip copying Web.config to ...ReleaseTransformWebConfigoriginalW
  eb.config, File ...ReleaseTransformWebConfigoriginalWeb.config i
  s up to date

And build fails with:

Transforming Source File: ...Web.config;Web.config
C:Program FilesMicrosoft Visual Studio2022ProfessionalMSBuildMicrosoftVisualStudiov17.0WebMicrosoft.Web.Publi
shing.targets(1552,5): error : Could not open Source file: Could not find file '...Web.config;Web.config'. [...Web.API.csproj]

Build command:

msbuild /p:configuration=release /p:DeployOnBuild=true /p:DebugType=None /p:SkipInvalidConfigurations=true /p:WarningLevel=0 

How can I rectify this issue? This is a .net framework project and having ability to transform web.config is quite important for us.

2

Answers


  1. Chosen as BEST ANSWER

    In the end we had some mess with CSPROJ file itself... What works for us is:

    <ItemGroup>
        <None Include="Web.Debug.config">
          <IsTransformFile>true</IsTransformFile>
          <DependentUpon>Web.config</DependentUpon>
          <CopyToOutputDirectory>Never</CopyToOutputDirectory>
        </None>
        <None Include="Web.Release.config">
          <IsTransformFile>true</IsTransformFile>
          <DependentUpon>Web.config</DependentUpon>
          <CopyToOutputDirectory>Never</CopyToOutputDirectory>
        </None>
        <None Include="Web.Test.config">
          <IsTransformFile>true</IsTransformFile>
          <DependentUpon>Web.config</DependentUpon>
          <CopyToOutputDirectory>Never</CopyToOutputDirectory>
        </None>
    </ItemGroup>
     .....
    <ItemGroup>    
        <Content Update="Web.config">
            <CopyToOutputDirectory>Never</CopyToOutputDirectory>
            <TransformOnBuild>true</TransformOnBuild>
        </Content>
        <Content Update="Web.Debug.config">
            <IsTransformFile>true</IsTransformFile>
            <DependentUpon>Web.config</DependentUpon>
            <CopyToOutputDirectory>Never</CopyToOutputDirectory>
        </Content>
        <Content Update="Web.Release.config">
            <IsTransformFile>true</IsTransformFile>
            <DependentUpon>Web.config</DependentUpon>
            <CopyToOutputDirectory>Never</CopyToOutputDirectory>
        </Content>
    </ItemGroup>
    

  2. This happened when a project was migrated to SDK-style, while keeping the explicit Content items.

    Fix: Add <EnableWebFormsDefaultItems>false</EnableWebFormsDefaultItems> or remove the explicit items.

    Original answer copied from:
    https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/issues/60

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search