创建完整.NET单一来源项目,PCL和DOTNET核心组件来自相同的C#源代码编译? [英] Create a single source project with full .net, PCL and dotnet core assemblies build from same C# source?

查看:670
本文介绍了创建完整.NET单一来源项目,PCL和DOTNET核心组件来自相同的C#源代码编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio 2015年,更新3,我试图找出存在会阻止我做以下的电流限制:

Using Visual Studio 2015, update 3, I am trying to find out the current limitations that exist that would prevent me from doing the following:


  1. 有关一个C#代码库,编译来自同一来源的一个完整的.NET Framework版本和PCL版本和.NET核心类库。

  1. For a single C# codebase, compile a full .net framework version and a PCL version, and a .net core class library from the same sources.

解决方案目录 solutiondir\ 将包含其中包含一个 src\ DIR > projectdir\ ( Solutiondir\src\projectdir )。

Solution dir solutiondir\ will contain a src\ dir which contains a projectdir\ (Solutiondir\src\projectdir).

PROJECTDIR 将包含的 HelloWorldPCL 的是建成一个类库经典.net PCL 项目,并与其他框架的目标也是如此。

Projectdir will contain a HelloWorldPCL class library which is built as a classic .net PCL project, and with other framework targets as well.

从同一个 PROJECTDIR 相同的 HelloWorldPCL 的也将被编译为 .NET 4.6 项目。

From the same Projectdir the same HelloWorldPCL will also be compiled for .net 4.6 project.

在同一个 PROJECTDIR 相同的 HelloWorldPCL 的也将被编译为 .NET核心

From the same Projectdir the same HelloWorldPCL will also be compiled for .net core.

以上所有的输出组件的共享访问一组C#代码,可能有一些#如果DOTNET #如果NET46 #如果PCL 有条件的定义来处理事情是不具备的各种框架/环境。

All of the output assemblies above will share access to a single set of C# code which may have some #if DOTNET and #if NET46 and #if PCL conditional defines to handle things which are not available in various frameworks/environments.

到目前为止,我所能做的最上面的,但是当我尝试有 PROJECTDIR 包含 .NET核心神器像 project.json HelloWorldCore.xproj 时,IDE给了我许多错误,如果我试图创建单独的 .csproj的。在同一文件夹xproj 的项目,这样似乎不是以正确的方式去。

So far I can do most of the above, but when I try to have the Projectdir contain a .net core artifact like project.json or HelloWorldCore.xproj, the IDE gives me many errors if I try to create separate .csproj and .xproj projects in the same folder, so that appears not to be the right way to go.

通过工作 .csproj的项目时,我引入一个 .xproj project.json 在磁盘上,但我们还没有添加这些到解决方案本身,他们只是在真正的项目源旁边的盘坐在那里,我得到的NuGet包还原错误,只能进行删除走开了 project.json 文件,所以显然这是不可能有一个 .csproj的在项目目录中,也有一个 project.json 文件夹中。一个人必须 project.json 之间进行选择模式( .NET核心项目样式)和的.csproj 模式(经典的C#项目样式)。

With a working .csproj project when I introduce an .xproj and a project.json on disk, but we have not added these to the solution itself, they are just sitting there on the disk beside the Real Project Sources, I get a Nuget package restore error, which can only be made to go away by deleting the project.json file, so clearly it is not possible to have a .csproj in a project directory and also have a project.json folder. One must choose between project.json mode (.net core project style) and .csproj mode (classic C# project style).

我建立了一个破的基本代码,演示了使用含有一个文件夹的可能性 .csproj的 project.json ,然后试图建立的csproj project.json 项目互不干扰:

I have built a "broken" codebase that demonstrates the impossibility of using a folder containing both a .csproj and a project.json and then trying to build the csproj and project.json project without them interfering:

https://bitbucket.org/wpostma/helloworldcoreandpcl

:有没有建立从一组C#源文件的项目,并为你的目标,一个完整的 .NET 4.6 集会,也是一个原生<$任何方式C $ C> .NET核心类库,也是一个PCL组件,其可能针对任何特定的.NET的个人资料?

Question: is there ANY way to build a project from a single set of C# source files, and have as your targets, a full .net 4.6 assembly, and also a native .net core class library, and also a PCL assembly which might target any particular .net profile?

异议:您可以正确地问:你不应该只使用一个PCL,并用它做的,忘记针对完整的.NET或创建一个单独的 .NET核心类库DLL?。也许如果代码可以建立一次,从单一来源,无需任何条件定义,且无在功能性的任何差异,如果由一个最低公分母PCL的 netstandard 的轮廓的方法所造成的限制充足,你可以。那如果这还没有可能的情况下?

Objection: You may rightly ask "shouldn't you just use one PCL and have done with it, and forget targeting full .net or creating a separate .net core class library dll?". Maybe if the code could be built once, from a single source, without any conditional defines, and without any differences in functionality and if the limitations imposed by a lowest-common-denominator PCL "netstandard" profile approach were sufficient, you could. But what about the cases where that's not even possible?

我们是否有一些复杂的构建过程中,我们无论是副本的项目文件或移动的源代码,以实现单的.cs 源文件目标的多个.NET轮廓nerdvana? ?还是我俯瞰替代解决方案。

Do we have to have some elaborate build process where we either copy project files or move source code around, in order to achieve single .cs source file target multiple .net profile nerdvana? Or am I overlooking alternative solutions?

更新:这似乎在与Visual Studio IDE,它阻止你直接添加引用的问题一个类库在解决方案中,当你使用 project.json 而不是使用 .csproj的构建它。但是下面由Jon指定的解决方案表明,你应该建立你的项目,再建一个的NuGet包 DOTNET包。如果你在我修改的演示看这里,你可以的 pack.cmd 文件包含我过去收拾一个的NuGet包的步骤,然后在本地发布到一个文件(本地目录)我个人的使用的NuGet饲料。

Update: It appears there is a problem with the Visual Studio IDE that prevents you from directly adding a reference to a class library in your solution, when you build it with a project.json instead of using a .csproj. However the solution below specified by Jon indicates that you should build your project, then build a nuget package with dotnet pack. If you look at my modified demo here you can the pack.cmd file contains the steps I used to pack up a nuget package, and then locally "publish" it to a file (local directory) nuget feed for my own personal use.

推荐答案

我会尝试去一个纯粹的 project.json 办法。例如,下面的这将会建立一个单一封装支持 netstandard1.0 ,PCL轮廓328 project.json 文件和.NET 4.6 - 与每一个配置定义了自己的符号,所以你可以有条件代码

I would try to go for a pure project.json approach. For example, here's a project.json file which will build a single package which supports netstandard1.0, PCL profile 328, and .NET 4.6 - with each configuration defining its own symbols so you can have conditional code.

{
  "version": "1.0.0",

  "frameworks": {
    "net46": {
      "buildOptions": {
        "define": [ "NET46" ]
      }
    },

    "netstandard1.0": {
      "buildOptions": {
        "define": [ "CORE" ]
      },
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    },

    ".NETPortable,Version=v4.0,Profile=Profile328": {
      "buildOptions": {
        "define": [ "PCL" ]
      },
      "frameworkAssemblies": {
         "mscorlib": "",
         "System": "",
       }
    }
  }
}

然后,只需使用 DOTNET包来创建的NuGet包。 (适用于所有其他元数据等加入后)。

Then just use dotnet pack to create the nuget package. (After adding in all the other metadata etc.)

这篇关于创建完整.NET单一来源项目,PCL和DOTNET核心组件来自相同的C#源代码编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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