I am trying to build some applications programmatically, using Microsoft.Build.Execution, however I have encountered the following error:
The "TransformTemplates" task was not loaded from assembly C:\Program Files (x86)\Microsoft Visual Studio \2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\TextTemplating\Microsoft.TextTemplating.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version = 15.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the 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 code implemented:
Dictionary<string, string> globalProperties = new Dictionary<string, string>() {
{ "RebuildT4Templates" , "true" },
{ "VSToolsPath", @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0" },
{ "LangVersion", "6" },
{ "ToolsVersion", "15.0" },
{ "VisualStudioVersion", "15.0" }
};
var manager = BuildManager.DefaultBuildManager;
var buildLoggger = new InMemoryBuildLogger();
var buildParameters = new BuildParameters() { Loggers = new[] { buildLoggger } };
var buildRequestData = new BuildRequestData(csProj, globalProperties, null, new[] { "Rebuild" }, null);
var buildResult = manager.Build(buildParameters, buildRequestData);
.Csproj file that I'm trying to build.
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<!-- Run the Transform task at the start of every build -->
<TransformOnBuild>true</TransformOnBuild>
<!-- -->
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<!-- Transform every template every time -->
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<!-- add AFTER import for $(MSBuildToolsPath)\Microsoft.CSharp.targets -->
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<ItemGroup>
<T4ParameterValues Include="BuildConfiguration">
<Value>$(Configuration)</Value>
<Visible>False</Visible>
</T4ParameterValues>
</ItemGroup>
<Target Name="CreateT4ItemListsForMSBuildCustomTool" BeforeTargets="CreateT4ItemLists" AfterTargets="SelectItemsForTransform">
<ItemGroup>
<T4Transform Include="@(CreateT4ItemListsInputs)" Condition="'%(CreateT4ItemListsInputs.Generator)' == 'MSBuild:TransformAll'" />
</ItemGroup>
</Target>
Any ideas on how to fix this? it seems that MSBuild does not have the necessary dependencies to build T4Template
Microsoft.Build.Utilities.Core.dll
in your project? What is the assembly dll version of it? Did you try to useC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Build.Utilities.Core.dll
? – Mr Qian