Visual Studio 2013 Typescript 编译器不尊重“_references.ts"文件 [英] Visual Studio 2013 Typescript compiler isn't respecting '_references.ts' file

查看:35
本文介绍了Visual Studio 2013 Typescript 编译器不尊重“_references.ts"文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Typescript 的新手,最近几天一直在使用 Visual Studio 2013 Update 2(本机包含所有支持).

I'm new to Typescript and have been working the last few days within Visual Studio 2013 Update 2 (which natively includes all support).

我在 Visual Studio 的项目属性页面上选择了以下选项.

I have the following options selected within Visual Studio on the properties page for my project.

这意味着当我保存文件时,它会自动将所有打字稿文件编译在一起并创建一个 RRStore.js 文件.然后我只是使用 ASP.NET 中的 BundleManager 包含它,就好像它是任何旧的 JS 文件一样.我没有使用模块加载器,因为没有太多的 JS 代码.

This means that when I save a file it will automatically compile all the typescript files together and create a single RRStore.js file. I then just include this using the BundleManager in ASP.NET as if it were any old JS file. I am not using a module loaders since there's not much JS code.

为了以正确的顺序解决依赖关系,TS 编译器需要一个 _references.ts 文件,所以我创建了一个这样的:

To resolve dependencies in the correct order the TS compiler needs a _references.ts file so I created one like this :

/// <reference path="RR.ErrorHandling.ts" />
/// <reference path="RR.JQueryPlugins.ts" />
/// <reference path="RR.Util.ts" />

/// <reference path="viewmodel/UserViewModel.ts" />

/// <reference path="viewmodel/AddressViewModel.ts" />
/// <reference path="viewmodel/ProductViewModel.ts" />
/// <reference path="viewmodel/CartItemViewModel.ts" />
/// <reference path="viewmodel/CheckoutViewModel.ts" />

/// <reference path="viewmodel/StoreWizardViewModel.ts" />
/// <reference path="viewmodel/DefenderWizardViewModel.ts" />

/// <reference path="viewmodel/MainViewModel.ts" />

/// <reference path="RR.YoutubeLoader.ts" />

此文件意味着当我在编辑 TS 文件后在 Visual Studio 中点击 Ctrl+S 时,它将按此顺序将我所有其他 TS 文件组合在一起,因此诸如原型链之类的东西对于继承是正确的.

This file means when I hit Ctrl+S within Visual Studio after editing a TS file it will combine all my other TS files together in this order so things such as prototype chains are correct for inheritance.

当保存 TS 文件时,这在 Ctrl+S 上运行良好.

This was working fine on Ctrl+S when saving a TS file.

然后我不得不对一些 C# 代码进行更改 - 之后我当然需要点击 Ctrl+F5 来构建项目.令我惊讶的是,我在浏览器中遇到了奇怪的 JS 错误——关于对象上不存在的原型.

I then had to make a change to some C# code - after which of course I needed to hit Ctrl+F5 to build the project. To my surprise I got weird JS errors in the browser - about prototypes not existing on objects.

我在浏览器中查看了生成的 Typescript 文件 RRStore.js 并检查了我所有文件的顺序,它把文件 RR.YoutubeLoader.ts 放在首位.

I looked at the generated Typescript file RRStore.js in the browser and examined the order of all my files and it's put the file RR.YoutubeLoader.ts FIRST.

这很奇怪!(尤其是因为它在我上面的参考文献列表中排在最后.)

That's weird! (not least because it's LAST on my list of references above.)

我转到那个文件并点击Ctrl+S,刷新RRStore.js,一切又回到了正确的顺序.

I went to that file and hit Ctrl+S, refreshed RRStore.js and everything is back in the right order.

换句话说,当我进行完整构建时,_references.ts 中的文件顺序不受尊重,但是当我点击 Ctrl+S 时,它是.怎么回事?

In other words when I do a full build the order of files in _references.ts is not respected, but when I just hit Ctrl+S it is. What's going on?

推荐答案

更新:结果 _references.ts 需要在项目的根目录中被编译器识别.所以这是首选方法:-) 这种方法也有效......但请不要这样做:

Update: Turns out _references.ts needs to be in the root of your project to be recognized by the compiler. So that's the preferred way :-) This method works too... but please don't do this:

原始解决方法:

在阅读我生成的 RRStore.js 文件时,我注意到顺序似乎是随机的:RR.YoutubeLoader, ProductViewModelDefenderViewModelStoreViewModel

When reading through my generated RRStore.js file I noticed the order seemed to be in an apparently random order: RR.YoutubeLoader, ProductViewModel, DefenderViewModel, StoreViewModel etc.

我意识到可能只有一种解释....

I realized there could be only one explanation....

我打开了 .csproj 文件,果然编译器按照文件最初添加到我的项目的顺序处理文件!!!.

I opened up the .csproj file and sure enough the compiler was processing files in the order they had been initially added to my project!!!.

所以我将 _references.ts 文件移到 MySite.csproj 文件中的第一个文件 - 现在它可以正确识别它并以正确的顺序编译所有内容.

So I moved the _references.ts file up to the first in the MySite.csproj file - and it is now correctly recognizing it and compiling everything in the right order.

我不确定这是否是一个已知的错误,但对我来说这是一个足够的解决方案.

I'm not sure if this is a known bug yet but that was an adequate solution for me.

这篇关于Visual Studio 2013 Typescript 编译器不尊重“_references.ts"文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆