Typescript: Microsoft.TypeScript.MSBuild.2.1.4 error

Created on 8 Dec 2016  ·  15Comments  ·  Source: microsoft/TypeScript

TypeScript Version: 2.1.4

After upgrading to TypeScript 2.1.4 and updating to Microsoft.TypeScript.MSBuild.2.1.4 via Nuget, we're getting the following error on our TeamCity build server when attempting to build a .csproj project targeting .NET 4.5 on a server with .NET Framework 4.5.2 installed:

C:TeamCity\buildAgent\work\127334233d38d231\packages\Microsoft.TypeScript.MSBuild.2.1.4\tools\microsoft.TypeScript.targets(195, 5): error MSB4018: The "VsTsc" task failed unexpectedly.
System.MissingMethodException: Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)'.
at TypeScript.Tasks.VsTsc.GenerateResponseFileCommands()
at Microsoft.Build.Utilities.ToolTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

This worked fine on TypeScript 2.0.3, the only change was moving from Microsoft.TypeScript.MSBuild.2.0.3 to Microsoft.TypeScript.MSBuild.2.1.4 and changing the TypeScriptToolsVersion in the .csproj project file from 2.0 to 2.1.

The error seems to be related to using a String.Format overload that only exists in .NET 4.6:

http://stackoverflow.com/a/30559657

https://msdn.microsoft.com/en-us/library/dn906224(v=vs.110).aspx

Is it possible this is a bug with the Microsoft.TypeScript.MSBuild.2.1.4 build target on .NET 4.5? Ideally we could run this on .NET 4.5 without modification. Any suggested fixes/workarounds?

Bug Fixed

Most helpful comment

Yep that is the plan 👍 Also this change will be release in the Nuget first. Once it checked it (hopefully soon) I will post it here

All 15 comments

While I haven't had a chance to try out this exact setup, your assessment seems correct to me (thank you!) - we did take a dependency on .NET Framework 4.6 in the MSBuild tasks. Unfortunately the only workaround I can think of at the moment is to actually install the 4.6 Framework.

We may consider downgrading the dependency back to 4.5 in the next release -- in the meantime, is there a reason you want to avoid the upgrade to 4.6?

We've actually run into some problems with .NET 4.6 in the past and reverted back to 4.5 (long story). It would be great if it could be fixed in a future version of the Microsoft.TypeScript.MSBuild NuGet package, I'm sure there are other people who aren't on .NET 4.6 yet that would like to use the MSBuild target. For now we'll just wait to upgrade to TS 2.1.

From that StackOverflow page (http://stackoverflow.com/a/30559657), it looks like the fix is to "just" change String.Format(a, b, c) to String.Format(a, b, new object[] { c }. There may be more to it than that though. :)

Thanks!

Hey all, great work on the progress of the 2.2 release.

Just wondering if you can share your thoughts behind moving this issue to 2.3 and whether or not it is something that is likely to be 'fixed' (I understand that it works as intended, but doesn't work on < .NET 4.6).

We have a change in the works that rewrites the whole tasks and targets. we should be releasing this as nightly nuget package under myget in the next few days.

The fix is in our VS repository. We will have to our call to string.format similar to @shawng suggested. (String.Format(a, b, new object[] { c })) Here is the documentation for string.format that work in older .net framework.

Update: turned out we also use another .net46 feature "Array.Empty" as well....

Thanks @yuit . Will the Array.Empty (something like new []) be pushed to Typescript Git repo at the same time as the string.Format overload?

Yep that is the plan 👍 Also this change will be release in the Nuget first. Once it checked it (hopefully soon) I will post it here

With the latest Microsoft.TypeScript.MSBuild.2.2.1 Nuget package I'm still seeing the following error when attempting to build using .NET 4.5:

error MSB4018: The "VsTsc" task failed unexpectedly.
System.MissingMethodException: Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)'.
at TypeScript.Tasks.VsTsc.GenerateResponseFileCommands()
at Microsoft.Build.Utilities.ToolTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

@yuit, it sounded like there was a fix for this, did it not make it in to 2.2.1?

The issue is marked for TS2.3 (see milestone); so the fix is expected to be in TS2.3

I am seeing the same error and another error when I'm trying to build a new ASP.Net MVC Core project programmatically using Microsoft.Build version 15 from NuGet.

Project being built: New ASP.Net MVC Core Project, .net framework 4.6.2.
Project it is being built from: ASP.NET MVC 6, .net framework 4.6.2

I'm using Visual Studio 2017 (release).

Nuget package Microsoft.Typescript.MSBuild 2.2.1 is installed in the .Net Core project.

Nuget packages installed in MVC 6 project:

Microsoft.Build version 15.1.0.0
Microsoft.Build.Framework, version 15.1.0.0
Microsoft.Build.Tasks.Core, version 15.1.0.0
Microsoft.Build.Utilities.Core, version 15.1.0.0

Microsoft.CodeAnalysis (and all associated packages), version 2.0.0.0

I'm loading the ASP.Net MVC Core project successfully with

workspace = MSBuildWorkspace.Create(new Dictionary
{ { "Configuration", "Debug" } });

Then later I'm trying to build the project with this setup

Microsoft.Build.Evaluation.ProjectCollection pc = new Microsoft.Build.Evaluation.ProjectCollection();
pc.DefaultToolsVersion = "15.0";
Dictionary globalProperties = new Dictionary();
globalProperties.Add("Configuration", "Debug");
globalProperties.Add("Platform", "Any CPU");

var targetsToBuild = new[] { "Build" };
BuildRequestData buildRequest = new BuildRequestData(projectFullPath, globalProperties, "15.0", targetsToBuild, null);

Errors:

ERROR C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0TypeScript\Microsoft.TypeScript.targets(164,5): The "TypeScript.Tasks.FindConfigFiles" task could not be loaded from the assembly C:\UsersKurtI.nuget\packages\microsoft.typescript.msbuild\2.2.1\toolsTypeScript.tasks.dll. Could not load file or assembly 'Microsoft.Build.Framework, Version=4.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.
Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
: ERROR C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(129,5): The "GenerateRuntimeConfigurationFiles" task failed unexpectedly.
System.MissingMethodException: Method not found: 'Boolean NuGet.Frameworks.NuGetFramework.op_Equality(NuGet.Frameworks.NuGetFramework, NuGet.Frameworks.NuGetFramework)'.
at Microsoft.NET.Build.Tasks.LockFileExtensions.CreateProjectContext(LockFile lockFile, NuGetFramework framework, String runtime, String platformLibraryName)
at Microsoft.NET.Build.Tasks.GenerateRuntimeConfigurationFiles.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

1) Why is Typescript.Tasks.dll trying to load Microsoft.Build.Framework, Version=4.0.0.0?

2) I was of the impression that the second issue (the same as discussed in this thread) was not an issue in projects built for framework 4.6 and above?

@kurtgronbech we have made a change to our NuGet including the fix of this issue. Could you give this new NuGet a try and see it solves the issue...

here is the link to the latest NuGet Package: https://www.myget.org/gallery/typescript-preview

Sorry for the late reply, but I confirm that using the latest package from myget.org fixed my issue.

Previously, "dotnet build" did not work either with same error, but with the newest package it works.

Just for the record, using Microsoft.TypeScript.MsBuild version 2.2.2. from Nuget.org does not work for me.

@mhegazy Thanks for bringing back .NET 4.5 support in the upcomming release.
@minestarks Since you asked for reasons against upgrading: The problem is backwards compatilibity: So long as you don't need a .NET 4.6 feature, you don't have to upgrade. Now, if you develop a framework, you try to keep the lowest common denomitor possible (in this case .NET 4.5) for as long as possible, so you don't force an upgrade onto an unsuspecting project or a customer. This in turn means your CI/build environment also stays on .NET 4.5 and you can only use packages that only require .NET 4.5 to support your build infrastructure.

For build components this means, as long as MSBuild in the latest version requires only .NET 4.5, all MSBuild Tasks must, too.

@mhegazy I just found out that it's in fact not fixed, even though the NuGet package says 'net45'. Apparently, FindConfigFiles.FindConfigFilesOnDisk() is compiled using .NET 4.6.

This issue should please get reopened.

Was this page helpful?
0 / 5 - 0 ratings