简体   繁体   English

Typescript将解决方案拆分成几个项目

[英]Typescript split solution into several projects

I used ScriptSharp before it was frozen. 在冻结之前我使用了ScriptSharp。 Since TypeScript is a developing OOP language I decided to try it. 由于TypeScript是一种正在开发的OOP语言,我决定尝试它。 I use visual studio (if it matters). 我使用visual studio(如果重要的话)。 I have troubles making simple things I used to do in ScriptSharp. 我在ScriptSharp中制作简单的事情我遇到了麻烦。 I didn't expect it would be that difficult. 我没想到会那么困难。 What I want to do: 我想做的事:

  • Create project A (Class Library Project) with module AssemblyA. 使用模块AssemblyA创建项目A(类库项目)。 AssemblyA module will have some exported classes. AssemblyA模块将具有一些导出的类。
  • Create project B (Class Library Project) with module AssemblyB. 使用模块AssemblyB创建项目B(类库项目)。 AssemblyB will reference AssemblyA types and use them as parameter types and etc. AssemblyB将引用AssemblyA类型并将它们用作参数类型等。

Can you give me some guide how to make it work or sample? 你能给我一些如何使其工作或样品的指南吗? Thanks. 谢谢。

UPDATE: What's for I can add reference to another typescript project? 更新:什么是我可以添加对另一个打字稿项目的引用? It would be great if output of referenced project was copied to that project. 如果将引用项目的输出复制到该项目,那将是很好的。

Rather than having assemblies and modules, you have modules that can be organised into namespace-like hierarchies: 您可以将模块组织成类似命名空间的层次结构,而不是拥有程序集和模块:

Internal Modules 内部模块

Internal Module Example: 内部模块示例:

module AssemblyA {
    export module ModuleA {
        export class Example {

        }
    }   

    export module ModuleB {
        export class Example {

        }
    }
}

var x = new AssemblyA.ModuleA.Example();
var y = new AssemblyA.ModuleB.Example();

You can also define these internal modules across multiple files... 您还可以跨多个文件定义这些内部模块......

modulea.ts modulea.ts

module AssemblyA {
    export module ModuleA {
        export class Example {

        }
    }   
}

moduleb.ts moduleb.ts

///<reference path="./modulea.ts" />
module AssemblyA {  
    export module ModuleB {
        export class Example {

        }
    }
}

app.ts app.ts

///<reference path="./modulea.ts" />
///<reference path="./moduleb.ts" />
var x = new AssemblyA.ModuleA.Example();
var y = new AssemblyA.ModuleB.Example();

External Modules 外部模块

And if you want to write really large applications, you can use external modules (where the file represents the module). 如果您想编写非常大的应用程序,可以使用外部模块(文件代表模块)。

assemblya/modulea.ts assemblya / modulea.ts

    export class Example {

    }

assemblya/moduleb.ts assemblya / moduleb.ts

    export class Example {

    }

app.ts app.ts

import ModuleA = require('./assemblya/modulea');
import ModuleA = require('./assemblya/modulea');
var x = new ModuleA.Example();
var y = new ModuleB.Example();

I found a workaround for my problem: 我找到了解决问题的方法:

In project AssemblyA: 在项目AssemblyA中:

  1. Specify "Combine javascript output into file" to "..\\AssemblyB\\AssemblyA.js". 指定“将javascript输出合并到文件中”到“.. \\ AssemblyB \\ AssemblyA.js”。
  2. Set up Generate Declaration files into true. 将生成声明文件设置为true。

In project AssemblyB: 在项目AssemblyB中:

  1. Add reference for intellisense in app.ts ///<reference path="../AssemblyA/AssemblyA.d.ts" /> 在app.ts中添加intellisense的参考///<reference path="../AssemblyA/AssemblyA.d.ts" />
  2. Add reference to generated file in html: <script src="AssemblyA.js"></script> 在html中添加对生成文件的引用: <script src="AssemblyA.js"></script>

In project B you can use any namespace aliases (for example: import AssemblyANS2 = AssemblyA.NS2;) or fully qualified name. 在项目B中,您可以使用任何名称空间别名(例如:import AssemblyANS2 = AssemblyA.NS2;)或完全限定名称。 Put classes in different files, Use same module name and there is no need to refer to ts files. 将类放在不同的文件中,使用相同的模块名称,不需要引用ts文件。

What I didn't like is that referencing project doesn't make any sense, but I wanted steps 1-2-3-4 to be done automatically after adding reference. 我不喜欢的是引用项目没有任何意义,但我希望在添加引用后自动完成步骤1-2-3-4。 Also "Redirect javascript output to directory" setting doesn't work when "Combine javascript output into one file" is specified. 当指定“将javascript输出合并为一个文件”时,“将javascript输出重定向到目录”设置也不起作用。 It's also weird that I can specify file path in second options. 我可以在第二个选项中指定文件路径也很奇怪。 I expected these settings to be combined with Path.Combine. 我希望这些设置与Path.Combine结合使用。 Maybe my solution is not ideal, but it's exactly what I need. 也许我的解决方案并不理想,但这正是我所需要的。 Feel free to suggest better idea. 随意提出更好的主意。

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

相关问题 ASP MVC 4在多个项目中拆分 - ASP MVC 4 Split in several projects Visual Studio:在一个解决方案中创建多个项目? - Visual Studio: Creating several projects in ONE solution? 包含多个项目的解决方案的ClickOnce部署 - ClickOnce deployment for solution containing several projects 制作包含多个项目的可执行解决方案 - Make executable solution containing several projects GoogleTest在同一解决方案中几个C ++项目 - GoogleTest several C++ projects in the same solution 是否可以在其他项目中引用打字稿文件而无需将项目添加到解决方案中? - Is it possible to reference typescript files in other projects without adding projects to the solution? 解决方案项目跨越Visual Studio中的多个Web项目 - Solution items cross several web projects in Visual Studio 在一个解决方案 c# 上为多个项目使用 NLog - Using NLog for several projects on one solution c# 尝试将项目从主要解决方案中分离出来,而 Nuget 参考没有看到这些包 - Attempting to split projects out of a main solution and Nuget reference is not seeing the packages 如何在(解决方案&gt;添加&gt;现有网站…)项目中使用Typescript? - how to use Typescript in (Solution>Add>Existing Web Site …) projects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM