在 Typescript 和 Visual Studio Express 中定义共享库 [英] Defining shared library in Typescript and Visual Studio Express

查看:19
本文介绍了在 Typescript 和 Visual Studio Express 中定义共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了 ProjectA,使用 Typescript 在 Visual Studio 中编译和运行.我现在想设置 ProjectB,并使用 ProjectA 中的一些代码

I have ProjectA set up compiling and running in Visual Studio with Typescript. I now want to set up ProjectB, and use some of the code from ProjectA

所以如果我的目录结构是:

So if my directory structure is:

c:\workspace\ProjectA\src
c:\workspace\ProjectB\src
c:\workspace\shared\src

是否可以编辑 ProjectA 和 ProjectB .csproj 文件以指向共享的打字稿代码?

is it possible to edit ProjectA and ProjectB .csproj files to point to the shared typescript code?

谢谢

推荐答案

我已经通过将共享文件(TypeScript 文件和关联文件)放在共享文件夹中,然后使用 Add >现有项目 并在添加文件时选择Add As Link.

I have tested this by placing the shared files (the TypeScript file and associated files) in a shared folder and then using Add > Existing Item and selecting Add As Link when I add the files.

如果您使用引用注释,则需要使用相对路径 - 如果您将共享文件拖到本地 TypeScript 文件上,它将为您生成:

If you are using reference comments, you'll need to use the relative path - if you drag the shared file onto a local TypeScript file it will generate this for you:

/// <reference path="../../Shared/Logger.ts" />

您需要考虑您的部署策略.一种方法是将 JavaScript 文件设置为在构建时复制,以便它们都出现在您的 bin 文件夹中.

You will need to consider your deployment strategy. One way to do it would be to set the JavaScript files to copy on build, so they would all appear in your bin folder.

您可能还想考虑打包共享的内容 - 例如,您可以为它们制作 NuGet 包.

You might also want to consider packaging your shared stuff - you could make NuGet packages for them for example.

这篇关于在 Typescript 和 Visual Studio Express 中定义共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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