【问题标题】:Build .NET Standard Library 1.4 using .NET Framework 4.6.1 without visual studio在没有 Visual Studio 的情况下使用 .NET Framework 4.6.1 构建 .NET Standard Library 1.4
【发布时间】:2017-12-19 13:54:36
【问题描述】:

我们尝试使用 .NET Framework 4.6.1 构建 .NET Standard Library 1.4 项目,在 windows server 2012 RC2 中使用没有 Visual Studio 的命令提示符用于自动化目的。

我已经在服务器上安装了以下内容,

.Net Framework 4.6.1
.Net Framework 4.6.1 Targeting pack
Microsoft Build Tools 2015

这个 .NET 标准库项目说 ProjectA 被其他两个 .NET 标准库项目 ProjectB 和 ProjectC 引用。

将 ProjectA 保留为启动项目

当我尝试在 dotnet restore 之后使用 dotnet build cmd 编译 ProjectA 时,我收到以下错误,

C:\Document\ProjectA>dotnet build

Project ProjectA (.NETStandard,Version=v1.4) will be compiled because 
expected outputs are missing

Compiling ProjectA for .NETStandard,Version=v1.4
C:\Program Files\dotnet\dotnet.exe compile-csc 
@C:\Document\ProjectA\obj\Debug\netstandard1.4\dotnet-compile.rsp returned 
Exit Code 1

C:\Document\ProjectA\Sample.cs(1,17): error CS0234: The type or namespace name 
'ProjectB' does not exist in the namespace 'XYZ' (are you missing an 
 assembly reference?)

C:\Document\ProjectA\Sample.cs(2,17): error CS0234: The type or namespace name 
'ProjectC' does not exist in the namespace 'XYZ' (are you missing an 
 assembly reference?)

Compilation failed.
0 Warning(s)
2 Error(s)

请帮助我从命令提示符编译解决方案。 示例代码:

using XYZ.ProjectB;
using XYZ.ProjectC;
using System;


namespace XYZ.ProjectA
{
    public class Sample : ISample
    {
        public Void GetMessage()
        {
            var s=XYZ.ProjectB.GetList();
            Console.Write("");      
        }
    }
}

ProjectB 和 Project C 也是 .Netstandard Lib

【问题讨论】:

  • The type or namespace name 'ProjectB' does not exist in the namespace 'XYZ' 这说明了一切!,这些项目没有相同的根命名空间!
  • 感谢您的回复 Suraj。它存在于同一个命名空间中..它在Visual Studio中正确编译和执行..但是当我在命令提示符的帮助下编译时会抛出错误。
  • 您需要在ABC.cs提供代码
  • 包含在问题中
  • 您仍在使用 project.json 的任何原因?我强烈建议您更新到最终的 1.0 工具。它会让一切大大变得更简单。

标签: c# windows command-line msbuild .net-4.6.1


【解决方案1】:

我设法通过使用 MSBuild 构建项目来解决上述情况

正如我之前提到的,在服务器中安装了以下框架后,

 1. .Net Framework 4.6.1 
 2. .Net Framework 4.6.1 Targeting pack
 3. Microsoft Build Tools 201

我正在尝试从未安装 Visual Studio 的服务器构建面向 .NET Standard 的可移植项目,我设法将以下文件和文件夹从安装了 Visual Studio 的机器复制到我的构建服务器。

  1. C:\Program Files (x86)\Microsoft SDKs\Portable\v14.0
  2. C:\Program Files (x86)\MSBuild\Microsoft\Portable
  3. C:\Program Files (x86)\ReferenceAssemblies\Microsoft\Framework.NETPortable
  4. C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet

并在服务器上安装了Microsoft .NET Portable Library Reference Assemblies 4.6

然后调用 MsBuild 的版本来构建您的解决方案,

C:\Program Files (x86)\MSBuild\14.0\Bin\MsBuild.exe MySolution.sln 

以上步骤帮助我构建 .NET Standard Libarary 项目,而无需在构建服务器上安装 Visual Studio。

我希望以上信息对某人有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 2016-10-29
    相关资源
    最近更新 更多