I am using Scripty.MsBuild
to generate some files in a ASP.NET Core project. When I build from VS2017, the target runs successfully, but when I build via dotnet
, I get the error:
Scripty.MsBuild.targets(31,5): error MSB4062: The "ScriptyTask" task could not be loaded from the assembly C:\Users\geirsagberg\.nuget\packages\scripty.msbuild\0.7.4\build\\..\tools\Scripty.MsBuild.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
My current workaround is to disable Scripty.MsBuild
for Release
configuration:
<PackageReference Include="Scripty.MsBuild" Version="0.7.4" Condition="'$(Configuration)'=='Debug'" />
This lets me build from VS in debug mode, and build with dotnet
on the build server.
However, I still want to be able to do dotnet run
locally in debug mode (for running from VSCode). Therefore I need to include the PackageReference
conditionally, based on whether Visual Studio's MSBuild is running, or the dotnet
version. As far as I can tell, these two have the exact same version number; am I missing something?
Is there a property in MSBuild I can use to distinguish between the VS MSBuild and the dotnet
one?
NET Core applications are typically built using MSBuild or dotnet.exe . MSBuild and dotnet.exe don't require Visual Studio to be installed, but in order to use them, the following prerequisites are required on a build server: Visual Studio Build Tools installed.
If you have Visual Studio, then you already have MSBuild installed. With Visual Studio 2022, it's installed under the Visual Studio installation folder. For a typical default installation on Windows 10, MSBuild.exe is under the installation folder in MSBuild\Current\Bin.
A target profile is a subset of a target framework. For example, the . NET Framework 4 Client profile does not include references to the MSBuild assemblies.
Turns out there is a property MSBuildRuntimeType
that can be either Core
, Mono
or Full
. So I can do:
<PackageReference Include="Scripty.MsBuild" Version="0.7.4" Condition="'$(MSBuildRuntimeType)'!='Core'" />
Reference from SDK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With