C# VS2015 project.json编译排除

C# VS2015 project.json编译排除,c#,visual-studio-2013,visual-studio-2015,project.json,C#,Visual Studio 2013,Visual Studio 2015,Project.json,在VisualStudio2013中,通过使用编译器常量并修改项目的.csproj文件,我能够从编译中排除一些.cs文件 大概是这样的: { "frameworks": { "net451": { "dependencies": { } } }, "dependencies": { ... }, "buildOptions": { "define": [ "MY_COMPILER_CONSTANT" ] } } --mypro

在VisualStudio2013中,通过使用编译器常量并修改项目的.csproj文件,我能够从编译中排除一些.cs文件

大概是这样的:

{
  "frameworks": {
    "net451": {
      "dependencies": { }
    }
  },
  "dependencies": {
    ...
  },
  "buildOptions": {
    "define": [ "MY_COMPILER_CONSTANT" ]
  }
}
--myproject.csproj

<PropertyGroup>
  ...
  <DefineConstants>MY_COMPILER_CONSTANT</DevineConstants>
  ...
</PropertyGroup>
<ItemGroup>
  ...
  <Compile Include="myproject\myfile.cs" Condition="'$(Configuration)' != 'MY_COMPILER_CONSTANT'" />
  ...
</ItemGroup>

添加用于编译的文件似乎很简单。我假定它与buildOptions中的“compile”配置变量有关。我需要添加什么才能使编译器在生成时忽略myfile.cs?

右键单击源代码管理器中的.cs文件以显示“属性”窗格。在属性窗格中,将生成操作更改为“无”。不应编译该文件


尝试:
buildOptions->compile->exclude

例如,从我的
project.json
-如何从编译中排除整个
lib
文件夹:

"buildOptions": {
  "compile": {
    "exclude": [ "lib" ]
  }
}
或另一个例子:


有关更多信息,请查找。

注意

在未来的版本中,.NET核心工具将从project.json迁移到基于MSBuild的项目

建议在新的.NET核心项目中仍然使用project.json文件,因为在工具发布时,将有一个将项目转换为MSBuild的路径

有关更多信息,请参阅.NET博客上的文章和主题

"buildOptions": {
    "compile": ["*.cs"],
    "exclude": ["buggy/**/*.cs", "foo/**/*.*"],
    "publishExclude": ["something/**/*.*"],
    "resource": ["embed/**/*.*"]
}