小编Jar*_*uan的帖子

二进制格式在netstandard 1.5

根据.NET CoreFx API列表及其相关的.NET Platform Standard版本,System.Runtime.Serialization.Formatters从1.3开始被添加到.NET平台标准中,这很酷,但是当我尝试创建.Net时核心类库目标netstandard1.5在.Net Core RC2下,我无法使用它.

代码很简单,只是想要声明一个BinaryFormatter:

public class Problems {
    private System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _formatter;
}
Run Code Online (Sandbox Code Playgroud)

错误是:

错误CS0234名称空间"System.Runtime"中不存在类型或命名空间名称"序列化"(您是否缺少程序集引用?)

这是project.json,我没有做任何修改:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027",
  },

  "frameworks": {
    "netstandard1.5": {
      "imports": "dnxcore50"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

那么,我需要依赖的另一个包吗?为什么?对于列表中的所有API,网络标准名称不应该足够吗?

c# binaryformatter .net-core-rc2

4
推荐指数
1
解决办法
4415
查看次数

如何在多目标项目中仅在所有构建之前调用我的脚本

我只想在构建过程之前运行我的 powershell 脚本一次。在我看来,这应该很容易完成,只需在 PreBuildEvent 之前调用脚本即可。嗯,它确实适用于普通项目。

但是,对于多目标项目?在针对所有目标框架的每次构建之前,脚本将被多次调用。

这是我的项目文件,其中我针对 3 个框架:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net40;net45;netstandard1.4</TargetFrameworks>
    <AssemblyName>abc</AssemblyName>
    <Version>1.0.0</Version>
  </PropertyGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="PowerShell -ExecutionPolicy Unrestricted -File script.ps1/>
  </Target>
</Project>
Run Code Online (Sandbox Code Playgroud)

当我构建项目时,PreBuild 目标被调用了 3 次。

到目前为止,我已经尝试过:

1) 起初,我猜测构建是按顺序进行的,所以我向目标添加了一个条件:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition=" '$(TargetFramework)' == 'net40' ">
    <Exec Command="PowerShell -ExecutionPolicy Unrestricted -File script.ps1/>
  </Target>
Run Code Online (Sandbox Code Playgroud)

,这不起作用。事实证明,多目标构建是同时进行的。有时,net40 的构建会更晚,所以我的脚本没有在所有构建之前运行。

2)然后我尝试使用环境变量进行同步,但也没有成功。似乎构建没有共享环境变量。

3) 最后,我转向其他 …

msbuild prebuild multi-targeting

3
推荐指数
1
解决办法
885
查看次数