typescript 使用 ASP.net 4 MVC 时“tsc.exe”以代码 1 退出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38625035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:41:29  来源:igfitidea点击:

"tsc.exe" exited with code 1 when using ASP.net 4 MVC

asp.netasp.net-mvcangulartypescript

提问by Farshad Momtaz

I'm following the tutorial on TypeScript website to add TypeScript and Angular 2 to my ASP.net MVC project. The tutorial from Typescript website can be found here.

我正在按照 TypeScript 网站上的教程将 TypeScript 和 Angular 2 添加到我的 ASP.net MVC 项目中。可以在此处找到 Typescript 网站上的教程。

I have followed the tutorial point by point; however I keep getting the following error at the end:

我逐点遵循教程;但是最后我不断收到以下错误:

"tsc.exe" exited with code 1.

The project works perfectly up to adding Angular 2.

该项目非常适合添加 Angular 2。

I have tried installing Microsoft.TypeScript.MSBuild and Microsoft.TypeScript.Compiler as they were suggested here. However that didn't fix the problem.

我已经尝试安装 Microsoft.TypeScript.MSBuild 和 Microsoft.TypeScript.Compiler,因为它们是在这里建议的。然而这并没有解决问题。

Any ideas on how to fix this problem?

关于如何解决这个问题的任何想法?

采纳答案by Developer Wonk

I resolved the build issue in VisualStudio 2015 Update 3 by adding

我通过添加解决了 VisualStudio 2015 Update 3 中的构建问题

  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

to the visual studio .csproj file.

到 Visual Studio .csproj 文件。

回答by RGH

If you reached here while using one of these tutorials:
https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html#!#prereq4https://www.typescriptlang.org/docs/handbook/asp-net-4.html

如果您在使用这些教程之一时到达此处:
https: //angular.io/docs/ts/latest/cookbook/visual-studio-2015.html#!# prereq4 https://www.typescriptlang.org/docs/手册/asp-net-4.html

Try this method to install TypeScript 2.0: https://www.microsoft.com/en-us/download/details.aspx?id=48593

试试这个方法安装 TypeScript 2.0:https: //www.microsoft.com/en-us/download/details.aspx?id =48593

It seems npm adds TypeScript 2.0 to the local users folders instead of the common program folder where visual studio looks by default. The install above will add it to the common program folder, which visual studio will detect without changes to the environment variable.

似乎 npm 将 TypeScript 2.0 添加到本地用户文件夹而不是 Visual Studio 默认查找的公共程序文件夹。上面的安装会将它添加到公共程序文件夹中,visual studio 将在不更改环境变量的情况下检测到该文件夹​​。

HTH

HTH

回答by Chiarato

I solved this problem installing

我解决了这个问题安装

Nuget package

Nuget package

> Typescript 2.0.6 for Visual Studio 2015

回答by user6647739

Which version of tsc you have installed? You can check with tsc -v in npm console in visual studio. I had the latest version of tsc installed, but visual studio was still referring to the oldest version of tsc.

你安装了哪个版本的tsc?您可以在 Visual Studio 的 npm 控制台中使用 tsc -v 进行检查。我安装了最新版本的 tsc,但 Visual Studio 仍然指的是最旧版本的 tsc。

Check under - C:\Program Files (x86)\Microsoft SDKs\TypeScript to see if you the old versions of tsc as well.

检查 - C:\Program Files (x86)\Microsoft SDKs\TypeScript 以查看您是否也使用旧版本的 tsc。

I had to manually delete older version of tsc folder from the path, for visual studio to be able to pick up the latest version of tsc. Or,you can add path in the environment variable to point to the latest tsc.

我必须从路径中手动删除旧版本的 tsc 文件夹,以便 Visual Studio 能够获取最新版本的 tsc。或者,您可以在环境变量中添加路径以指向最新的 tsc。

回答by user6647739

So, what I did was - I deleted the folders from the path and just kept the folder of latest tsc version. After that if you run the command tsc - v from npm console in visual Studio it will show you the latest version.

所以,我所做的是 - 我从路径中删除了文件夹,只保留了最新 tsc 版本的文件夹。之后,如果您从 Visual Studio 中的 npm 控制台运行命令 tsc -v,它将显示最新版本。

After that if you still get the same error. You can then run the command "npm install" from npm console in visual Studio. Make sure you are in the directory where you have packages.json file. It will install node modules folder with all the libraries. Once that is done you should be able to compile your project.

之后,如果您仍然遇到相同的错误。然后,您可以从 Visual Studio 的 npm 控制台运行命令“npm install”。确保您位于包含 packages.json 文件的目录中。它将安装包含所有库的节点模块文件夹。完成后,您应该能够编译您的项目。

回答by Farshad Momtaz

I also found out that I should set the TypeScriptToolsVersioninside .csprojfile to the current version of Typescript installed on the PC. Visual Studio sometimes chooses the wrong version of the Typescript.

我还发现我应该将TypeScriptToolsVersion内部.csproj文件设置为 PC 上安装的当前版本的 Typescript。Visual Studio 有时会选择错误版本的 Typescript。