简体   繁体   English

在Visual Studio 2015 for Angular2上启动项目

[英]Starting a project on Visual Studio 2015 for Angular2

I used stackoverflow extesively to figure out how to get Angular2 working in Visual Studio 2015 pro. 我过分地使用stackoverflow来弄清楚如何使Angular2在Visual Studio 2015 pro中工作。 No real answers but here is what I found that worked. 没有真正的答案,但这是我发现有效的方法。 I have seen a bunch and I mean a bunch of instructions and examples for how to get Visual Studio 2015 Pro working with an Angular2 project. 我见过很多,我的意思是关于如何使Visual Studio 2015 Pro与Angular2项目一起使用的大量说明和示例。 Now this gets a little confusing with all the instructions using Visual Studio Community or use any other editor. 现在,这与使用Visual Studio社区或使用任何其他编辑器的所有说明有些混淆。 Here is what I have found using my own experimenting and also the beginning of a good book on the subject "Angular 2 Development with Typescript" by Yakov Fain and Anton Moiseev. 这是我通过自己的实验发现的内容,也是Yakov Fain和Anton Moiseev撰写的一本关于“使用打字稿进行角度2开发”主题的好书的开头。 Available from Manning publications. 可从曼宁出版物获得。 Anyway here is my basic setup for a project. 无论如何,这是我对项目的基本设置。

First install Nodejs, this is so you can use it for your package manager. 首先安装Nodejs,这样您就可以将其用于软件包管理器。 Don't mess with doing it through NuGet, just install the Windows install package from the website. 不要通过NuGet进行操作,只需从网站上安装Windows安装程序包即可。 Also I did try another pakcage manager but I think Node has the latest packages. 我也尝试了另一个pakcage管理器,但是我认为Node具有最新的软件包。 Next you can run npm init and it will create a default package.json file. 接下来,您可以运行npm init,它将创建一个默认的package.json文件。 Afterwards edit it and make it look more or less like the following: 然后对其进行编辑,使其大致上与以下内容类似:

{ 
  "name": "helloworld", 
  "version": "1.0.0", 
  "description": "test npm setup", 
  "main": "main.ts", 
  "scripts": { 
    "start": "live-server" 
  }, 
  "author": "name", 
  "license": "ISC", 
    "dependencies": { 
"angular2": "2.0.0-beta.0", 
"es6-promise": "^3.0.2", 
"es6-shim": "^0.33.3", 
"reflect-metadata": "0.1.2", 
"rxjs": "5.0.0-beta.0", 
"systemjs": "0.19.8", 
"zone.js": "0.5.10" 
}, 
"devDependencies": { 
"live-server": "^0.8.2", 
"typescript": "1.7.5" 
} 
} 

Now that you have the package.json file, next is to get a command prompt in your project directory and type the following: 现在您有了package.json文件,接下来是在项目目录中获得命令提示符,然后键入以下内容:

Npm install Npm安装

This will create a node_modules folder which will have all of the packages available for angular2. 这将创建一个node_modules文件夹,其中将包含所有可用于angular2的软件包。

Next you need to go to the project/properties/TypeScript Build section and click on "CommonJS" in Module System section of the page. 接下来,您需要转到project / properties / TypeScript Build部分,然后在页面的Module System部分中单击“ CommonJS”。 Next you need to right click on the project and unload it, the right click and edit. 接下来,您需要右键单击该项目并将其卸载,然后单击鼠标右键并进行编辑。 Look for the following section: 查找以下部分:

<PropertyGroup Condition="'$(Configuration)' == 'Debug'"> 

Down near the bottom of that section add the next two lines: 在该部分的底部附近添加以下两行:

<TypeScriptEmitDecoratorMetadata>True</TypeScriptEmitDecoratorMetadata> 
 <TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators> 

OK we are almost done. 好,我们快完成了。 You need to walk down the node_modules folder and find: 您需要遍历node_modules文件夹并找到:

/node_modules/typescript/lib/typescript.d.ts /node_modules/typescript/lib/typescript.d.ts

And include this in your project by right clicking on it and selecting include in project. 右键单击它,然后选择包含在项目中,然后将此包含在您的项目中。 I think there are some changes in this that make the VS install of typescript work with Angular2, not enough of an expert to know just know after a ton of trial an error that is the main key. 我认为这有一些变化,使VS安装Typescript可与Angular2一起使用,还不足以使专家知道,经过一番尝试后才知道错误是主要的关键。 Now I also because I do not like to see red squigles, go in to the Index.html or what ever you call your boot html page and find each of my include sources and include them, not essential just less irritating. 现在,我也因为我不喜欢看到红色的花样而进入Index.html或您所谓的启动html页面,找到我的每个include来源并将其包括在内,这并不那么麻烦。 Here are the includes I have to a basic app: 这是我必须具备的基本应用程序的内容:

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script> 
    <script src="node_modules/typescript/lib/typescript.js"></script> 
    <script src="node_modules/systemjs/dist/system.src.js"></script> 
    <script src="node_modules/rxjs/bundles/Rx.js"></script> 
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>

I can not believe how many hours I spent getting to this conclusion. 我不敢相信我花了几个小时得出这个结论。 I read multiple different and sometimes conflicting ways to make this work. 我读到了多种不同的,有时是相互矛盾的方法来完成这项工作。 I hope this helps a fellow newbie get over the hump! 我希望这可以帮助新手同行!

@M.Gamble - Assuming that your using ASP.NET Core web apps to run Angular 2 using VS 2015 then follow this link http://www.mithunvp.com/angular-2-in-asp-net-5-typescript-visual-studio-2015/ @ M.Gamble-假设您使用ASP.NET Core Web应用程序通过VS 2015运行Angular 2,然后点击此链接http://www.mithunvp.com/angular-2-in-asp-net-5-typescript-视觉工作室-2015 /

If your looking for ASP.NET MVC 5, then go through comments section of above link. 如果您正在寻找ASP.NET MVC 5,请通过上面链接的注释部分。 They might help you. 他们可能会帮助您。

After some recent experimentation, I found that if you add a tsconfig.json file to the root of the project you can avoid setting the keys in the project file. 经过最近的试验,我发现如果将tsconfig.json文件添加到项目的根目录,则可以避免在项目文件中设置密钥。 If Visual Studio 2015 finds a tsconfig file it will use that and gray out the normal TypeScript Build section of the properties. 如果Visual Studio 2015找到tsconfig文件,它将使用该文件并将属性的常规TypeScript Build部分显示为灰色。 One caveat if you add one after you start your project you might have to exit the project and even restart VS. 一个警告,如果在启动项目后添加一个警告,则可能必须退出该项目,甚至重新启动VS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio中打开独立的angular2和TypeScript项目 - How to open standalone angular2 and TypeScript project in visual studio 在 angular 项目 Visual Studio 代码上启动前端时出错 - Errors starting frontend on angular project visual studio code Visual Studio 2015 Blank Cordova项目中没有显示任何文件 - No files showing in a Visual Studio 2015 Blank Cordova project Visual Studio 2015:Angular 2 @Component无法解析类装饰器的签名 - Visual Studio 2015 : angular 2 @component unable to resolve signature of class decorator Angular2构建:仅在Visual Studio中找不到名称“ Promise” - Angular2 Build: Cannot find name 'Promise' only in Visual Studio Angular2与Maven项目 - Angular2 with maven project Visual Studio 2015中的AngularJS Intellisense - AngularJS Intellisense in Visual Studio 2015 Visual Studio 2015-Node.js,使用TypeScript项目的Express 4无法编译 - Visual studio 2015 - node.js, express 4 using typescript project does not compile Visual Studio 2015:将NodeFrame Project中的单元测试文件的TestFramework设置为Mocha的错误 - Visual Studio 2015: Bug setting TestFramework to Mocha for unit test files in NodeJS Project 在 Visual Studio 2015 中构建 node-gyp 项目时出现 LNK1104 错误 - LNK1104 error when building node-gyp project in Visual Studio 2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM