2016-08-24 145 views
1

我有一点VSCode创建C#程序和多个文件夹结构的问题。VSCode多个项目参考

例如,我有一个文件夹调用SampleProject1(我认为文件夹项目也许我错了)在这个文件夹中我有我的程序类,有我的测试应用程序的入口点,在本程序的主要方法类我引用了一个Test类,它存在于第二个文件夹中调用SampleProject2,但是当我运行该程序时,出现一个错误,表明我的测试类不存在。

我试过的东西做的很远。

  1. 我试图添加SampleProject2作为SampleProject1的project.json的依赖项,但没有奏效。
  2. 我为SampleProject 2运行dotnet包并作为SampleProject1的project.json的依赖项添加,并且也失败。
  3. 我也尝试运行“哟ASPNET”命令创建的csproj但我觉得不再有效见链接here
  4. 我去VSCode Github上并没有找到一个测试真正的C#示例(怪异)
在SampleProject1

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    "debugType": "portable", 
    "emitEntryPoint": true 
    }, 
    "dependencies": { 

    }, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.0.0" 
     } 
     }, 
     "imports": "dnxcore50" 
    } 
    } 
} 

的Program.cs

project.json上SampleProject1

using System; 
using SampleProject2; 

namespace SampleProject1 
{ 
    public class Program 
    { 
     public static void Main(string[] args) 
     { 
      var test = new TestClass(); 
      Console.WriteLine("Hello World!"); 
     } 
    } 
} 
在SampleProject2

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    "debugType": "portable" 
    }, 
    "dependencies": {}, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.0.0" 
     } 
     }, 
     "imports": "dnxcore50" 
    } 
    } 
} 

TestClass.cs 0

project.json上SampleProject2

namespace SampleProject2 
{ 

    public class TestClass 
    { 
     public int Id { get; set; } 
    } 

} 

更新: 我能够通过设置在项目的根文件夹来编译应用程序。但我不明白intelesense

VSCode Extructure enter image description here

编译错误命令Pront enter image description here

+0

检查VS代码的多个项目文档http://stackoverflow.com/documentation/vscode/7717/multiple-projects-set-up#t=201611030739421019893 – Artru

回答

0

我不能看到从截图误差作为其截断(您可以复制并粘贴错误,而不是它的屏幕截图?),但你已经声明TestClass(),但正试图例化TesClass(),所以它在这里看起来像一个简单的错字...

+0

是不是笔误,请参阅更新码 –

1

VSCode尚不支持C#项目。见GitHub的响应here和智能感知问题回答here

0

要构建的解决方案有多个项目添加一个依赖于外部库里面SampleProject1/project.json

"dependencies": { 
    "SampleProject2": "1.0.0-*" 
    }, 

然后启用智能感知使用OmniSharp feature多间切换项目。

由于SampleProject1依赖于SamleProject2,所以最好的方法是在两个项目(root)上指定OnmiSharp引擎。点击Select project,然后选择最适合您的设备。

enter image description here enter image description here