在另一个项目

时间:2018-01-12 01:14:56

标签: angularjs angular typescript visual-studio-2015

更新 - 我刚发现这篇文章:

http://blog.davidjs.com/2015/11/visualstudio-has-problem-when-multiple-versions-of-typescript-are-installed/

这表明我的问题可能是这样的:

  

VisualStudio使用文件lib.d.ts来学习窗口的接口   对象,事件等。此lib.d.ts随每个版本的更新而更新   你安装的打字稿。当某些界面过时时,它就是   从lib.d.ts中删除,然后VisualStudio标记这样的用法   接口无效并拒绝构建。

文章说:

  

您可以指定自己的lib.d.ts版本,以便在您的版本中使用   具体项目使用

/// <reference path=”custom/path/to/lib.d.ts” />
  

在项目特定的_reference.ts中   文件。

虽然如何做到这一点?编译器抱怨解决方案中没有构建的lib.d.ts,所以我必须指定lib.d.ts,以便lib.d.ts可以使用TypeScript 1.8?

问题:

我有一个包含许多项目的Visual Studio 2015解决方案。我已将其中一个项目(包含AngularJS)升级为使用TypeScript 2.6.2的混合AngularJS / Angular应用程序,现在同一解决方案中的其他项目之一(纯粹的AngularJS应用程序)无法编译,因为TypeScript错误。

新升级的项目正在编译(包括TypeScript),它使用以下tsconfig.json文件通过Visual Studio进行编译:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "noStrictGenericChecks": true
  },
  "include": [ "**/*.ts" ],
  "exclude": [
    "node_modules"
  ]
}

当我通过Windows中的命令行进入项目根文件夹,然后输入&#39; tsc -v&#39;,输出是版本2.6.2&#39;我认为确认Visual Studio针对此项目构建的TypeScript版本。

另一个项目(包含&#39;纯&#39; AngularJS代码)仅使用Visual Studio构建(没有使用CLI进行任何tsc编译)。该项目现在显示Visual Studio中之前没有的* .ts错误,包括以下内容:

enter image description here

我也看到了各种* .d.ts错误:

enter image description here

enter image description here

由于某些配置更改,必须显示错误,因为项目没有任何代码更改,但我不明白这一点,因为项目通过visual studio和进行编译没有使用tsconfig.json,项目设置没有改变。他们在这里:

enter image description here

相关的.csproj设置:

<PropertyGroup>
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptToolsVersion>1.8</TypeScriptToolsVersion>    
    ... etc

当我获得“混合动力车”时Angular / AngularJS项目工作,在一个阶段我安装了TypeScript编译器v.2.6.2&#39;使用VS nuget包管理器在Visual Studio解决方案中进行全局操作,但是我已经卸载了它,并且没有任何内容写入源代码控制下的packages.config文件。在任何情况下,&#39; TypeScriptToolsVersion&#39;在该项目中,仍然指向v1.8,所以我不认为安装/卸载nuget包是导致问题的原因。以下是我在编译TypeScript时Visual Studio通常使用的C:\ Program Files(x86)\ Microsoft SDKs \ TypeScript文件夹中的内容

enter image description here

我注意到&#39;版本&#39;文件有&#39; LastKnownTypeScriptVersion&#39; 2.6如下所示,但是当我将其编辑为1.8时,当我关闭并重新打开Visual Studio时,现在无法加载具有错误的项目

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <LastKnownTypeScriptVersion>2.6</LastKnownTypeScriptVersion>
  </PropertyGroup>
</Project>

当我配置混合应用程序时,我还进行了全新的TypeScript 2.6.2安装,以及在新的混合应用程序中安装了TypeScript 2.6.2的npm。项目,但Visual Studio不应该使用那些,因为那些应该完全独立安装TypeScript。

这里有什么明显的遗漏吗?我需要更多关于我能看到的想法。任何评论或答案给我一些关于发生了什么或我能看到什么的线索将不胜感激!

1 个答案:

答案 0 :(得分:0)

我发现问题可能是最初从VSX15安装了适用于VS2015的TypeScript 2.6.2:

https://www.microsoft.com/en-us/download/details.aspx?id=48593

在我卸载并重新安装之后,除了另一个(完全不同的)项目无法加载之外,一切正常 - 我必须右键单击并“重新加载项目”才有效。我在混合应用程序中遇到错误,当我尝试打开一个JavaScript文件“没有找到符合约束合同名称的导出”时,我按照这篇文章中的建议来解决它:

Error message "No exports were found that match the constraint contract name"

我特别需要为Visual Studio 2015包安装TypeScript(而不是TypeScript 2.6.2编译器nuget包),以修复我最初创建时在Visual Studio中为混合AngularJS / Angular应用程序获得的一些错误它

Visual Studio似乎没有简单地根据.csproj文件中的<TypeScriptToolsVersion>1.8</TypeScriptToolsVersion>正确管理依赖项,因为这些是为所有项目正确配置的