【问题标题】:ASP.Net Core solution publishing wrong projectASP.Net Core 解决方案发布错误项目
【发布时间】:2016-10-06 22:48:17
【问题描述】:

我创建了一个新的 ASP.Net 核心项目并将其设置在源代码控制中,当我签入时它会发布到 Azure。我能够正确设置所有内容并且工作正常。

但是,我随后向解决方案添加了一个类库项目,现在 MSBuild 任务不是发布我的网站项目,而是尝试发布我的类库,这当然会失败。

部署命令中的行是:

"%MSBUILD_PATH%" "%DEPLOYMENT_SOURCE%\MySolution.sln" /nologo /verbosity:m /p:deployOnBuild=True;AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false;publishUrl="%DEPLOYMENT_TEMP%"

当它运行时,它首先构建模型项目,这很好:

 D:\Program Files (x86)\dotnet\dotnet.exe build "D:\home\site\repository\MySolution.Models" --configuration Release --no-dependencies

但随后它也会尝试发布该项目:

D:\Program Files (x86)\dotnet\dotnet.exe publish "D:\home\site\repository\MySolution.Models" --output "D:\local\Temp\PublishTemp\MySolution.Models71" --configuration Release --no-build
D:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(149,5): error : Can not find runtime target for framework '.NETStandard,Version=v1.6' compatible with one of the target runtimes: 'win8-x86, win7-x86'. Possible causes: [D:\home\site\repository\MySolution.Models\MySolution.Models.xproj]

哪个是错误的项目(应该是 web 项目)。我似乎找不到任何包含此设置或解决方案文件本身中的设置的文件。

我需要做什么才能发布正确的项目?

【问题讨论】:

  • 尝试使用指定的project.json发布:dotnet publish ~/projects/app1/project.json
  • 那么把MSBuild任务改成不在build时部署然后手动部署?这可能行得通,但似乎必须有一种方法来指定要部署的项目。

标签: azure msbuild asp.net-core


【解决方案1】:

我可以分两步解决这个问题。

首先从 msbuild 命令中删除 deployOnBuild=True 和 publishUrl=[snip]。这意味着此步骤将构建项目但不进行任何发布。

接下来添加一个执行发布的新步骤。

为此,我首先创建了一个新变量来保存 dotnet.exe 的位置:

IF DEFINED DOTNET_PATH goto DotNetPathDefined
SET DOTNET_PATH=%ProgramFiles(x86)%\dotnet\dotnet.exe
:DotNetPathDefined

然后添加以下内容以进行 web 项目的发布:

call :ExecuteCmd "%DOTNET_PATH%" publish "%DEPLOYMENT_SOURCE%\MySolution.Web" --framework netcoreapp1.0 --output "%DEPLOYMENT_TEMP%" --configuration Release --no-build
IF !ERRORLEVEL! NEQ 0 goto error

这会将所有文件发布到部署临时文件夹,然后使用 KuduSync 步骤进行部署。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-16
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多