使用Microsoft.Build.Evaluation以编程方式发布时启用NuGet还原

时间:2018-06-28 12:23:57

标签: c# msbuild

我正在尝试使用下面的代码发布使用Microsoft.Build.Evaluation库的Web应用程序。但是,以下执行失败的项目带有提及启用NuGet还原的错误消息。错误消息中提供的链接无效,因为它显示了如何在Visual Studio IDE中启用NuGet还原。

请让我知道使用Microsoft.Build.Evaluation以编程方式发布Web应用程序时如何启用NuGet。

Build FAILED.

C:\x\Dnn.Platform-development\DNN Platform\DotNetNuke.Web\DotNetNuke.Web.csproj(419,5): error : This project references NuGet package(s) that are missing on this computer.Enable NuGet Package Restore to download them.For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\..\..\Evoq.Content\\.nuget\NuGet.targets.
    0 Warning(s)
    1 Error(s)

用于发布Web应用程序的源代码:

using B = Microsoft.Build.Evaluation;
using Microsoft.Build.Logging;
using Microsoft.Build.Framework;
using System.IO;
using System.Collections.Generic;

namespace WebPublisherTest
{
    class Program
    {
        static private readonly string RootTempFolder = @"C:\TST";
        static private readonly string PublishDropFolderName = "PublishDrop";
        static private readonly string ToolVersion = "12.0";

        static void Main(string[] args)
        {
            string projectFilePath = @"C:\x\Dnn.Platform-development\DNN Platform\Admin Modules\Dnn.Modules.Console\Dnn.Modules.Console.csproj";
            string tempLocation = Path.Combine(RootTempFolder, Path.GetRandomFileName());
            string publishDrop = Path.Combine(tempLocation, PublishDropFolderName);

            var globalProperty = new Dictionary<string, string>
                {
                    { "Configuration", "Debug" },
                    { "OutputPath", publishDrop },
                    { "WebPublishMethod", "FileSystem" }
                };

            ConsoleLogger logger = new ConsoleLogger(verbosity: LoggerVerbosity.Normal);

            B.Project p = new B.Project(projectFilePath, globalProperty, ToolVersion);
            p.Build(new List<ILogger>() { logger });
        }
    }
}

0 个答案:

没有答案