I have multiple .NET Framework 4.8 ASP.Net web apps in the same solution. They are still using packages.config
and are using Microsoft.CodeDom.Providers.DotNetCompilerPlatform
version 4.1.0
.
Consistently and reproducibly I get this problem of the roslyn
folder not being created in the bin
folder when building in Visual Studio 2022. To reproduce:
- Close Visual Studio 2022
- Delete the
packages
folder and all theobj
andbin
folders - Open Visual Studio 2022
- Restore Nuget packages for the solution (confirm that
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
exists inpackages
folder). - Build solution.
Every single time the bin
folders of the web apps do not contain the roslyn
folder. I have to do multiple cleans and builds and/or rebuilds and eventually the roslyn
folder shows up and the web apps work. I haven't been able to identify a pattern as to when a build will finally copy the roslyn
folder.
Solution
I have updated the .csproj
files of the web apps to include
<PropertyGroup><RoslynCopyToOutDir Condition="$(RoslynCopyToOutDir) == ''">true</RoslynCopyToOutDir><RoslynToolPath Condition="'$(RoslynToolPath)' == ''">..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\tools\Roslyn-4.1.0</RoslynToolPath></PropertyGroup>
Now following the same reproduction steps above the roslyn
folder is copied to the bin
folder the very first time the solution is built.
I copied this from the Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets
file located in \packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472
.
Since this now works consistently I am assuming something is going wrong with the import of the targets configured in the .csproj
files. They do contain the below import statement, so I am not sure what is interfering with the imports intermittently.
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"><PropertyGroup><ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText></PropertyGroup><Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets'))" /></Target><Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\build\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets')" />