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
In the end we had some mess with CSPROJ file itself... What works for us is:
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