Fixing MSB4019 Error: Microsoft.CSharp.Core.targets Not Found After Winget Install of Visual Studio 2019
After installing Visual Studio 2019 Professional using the Windows Package Manager (winget install Microsoft.VisualStudio.2019.Professional
), attempting to build a .NET Framework (e.g., v4.8) project using MSBuild or devenv.com
fails with the error:
error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found. Confirm that the expression in the Import declaration "..." is correct, and that the file exists on disk.
This occurs because the default winget
installation might be minimal and may not include all components required for older .NET Framework desktop development, even if the base product is installed. The build system specifically looks for C# core build targets within the VS 2019 installation path, not just in the modern .NET SDK path (like C:\Program Files\dotnet\sdk\...
).
Running MSBuild directly on a simple .NET Framework 4.8 project results in the MSB4019
error mentioned above. Commands like vs_installer.exe update
report no updates available, and vs_installer.exe repair
(especially in quiet mode) may not resolve the issue.
A Minimal Working Example (MWE) consisting of a basic HelloWorld.cs
and a corresponding .csproj
file targeting .NETFramework,Version=v4.8
, when built directly with MSBuild.exe
from the VS 2019 installation path ("C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"
), reproduced the exact MSB4019
error. This confirmed the issue was with the VS installation itself, not the specific project or NuGet dependencies.
The fix is to explicitly add the ".NET desktop development" workload to your Visual Studio 2019 installation using the Visual Studio Installer's command-line interface.
-
Open
cmd
orpowershell
as Administrator. -
Run the following command:
start "" /wait "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional" --add Microsoft.VisualStudio.Workload.ManagedDesktop --quiet --norestart
modify
: Tells the installer to change the existing installation.--installPath "..."
: Specifies the VS 2019 Professional installation directory.--add Microsoft.VisualStudio.Workload.ManagedDesktop
: Adds the ".NET desktop development" workload. This workload includes the necessary Roslyn compilers and MSBuild targets (Microsoft.CSharp.Core.targets
) for .NET Framework projects.--quiet
: Runs without showing the installer GUI.--norestart
: Prevents an automatic reboot if one is deemed necessary by the installer.start "" /wait
: Ensures the command prompt waits for the installer process to complete.
-
Check File Existence (Optional): After the modify command completes, you can verify the file now exists:
dir "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets"
-
Re-run MWE Build: Navigate back to the MWE directory (
C:\dev\msbuild_test
in the example) and run the MSBuild command again:"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe" HelloWorld.csproj /t:Build /p:Configuration=Release /p:Platform=AnyCPU /v:n
The build should now succeed.
A standard winget install
of Visual Studio 2019 Professional might require explicit modification using vs_installer.exe modify --add <WorkloadID>
to install specific workloads like ".NET desktop development" needed for certain project types (.NET Framework). Simply running update
or repair
might not be sufficient if the core workload components were never installed initially.
You can also achieve the same result using the Visual Studio Installer GUI:
- Run "Visual Studio Installer".
- Find your VS 2019 Professional installation and click "Modify".
- Go to the "Workloads" tab.
- Check the box for ".NET desktop development".
- Click "Modify" in the bottom right to apply the changes.