C# dotnet发布配置文件CLI与Visual Studio的行为不同

C# dotnet发布配置文件CLI与Visual Studio的行为不同,c#,msbuild,.net-core,C#,Msbuild,.net Core,我有一个dotnet core 2.1 web API项目,其中包含一个发布配置文件到一个文件夹,我最近计划将该文件夹复制到IIS,如中所示 我用VS创建了发布配置文件,结果文件是 <?xml version="1.0" encoding="utf-8"?> <!-- This file is used by the publish/package process of your Web project. You can customize the behavior of th

我有一个dotnet core 2.1 web API项目,其中包含一个发布配置文件到一个文件夹,我最近计划将该文件夹复制到IIS,如中所示

我用VS创建了发布配置文件,结果文件是

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <PublishProvider>FileSystem</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <ProjectGuid>b3155c62-817f-4eba-8856-e5941137f4ed</ProjectGuid>
    <SelfContained>true</SelfContained>
    <_IsPortable>false</_IsPortable>
    <publishUrl>bin\publish\</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

文件系统
文件系统
释放
任何CPU
真的
假的
netcoreapp2.1
win-x64
b3155c62-817f-4eba-8856-e5941137f4ed
真的
假的
bin\publish\
真的
如果我从VS运行配置文件,它将创建一个
bin\publish
文件夹,我可以将其复制到IIS

如果我在更新到最新VS后对
dotnet publish/p:PublishProfile=FolderProfile
(在CI服务器中)执行相同的操作,我会得到以下错误

C:\Program Files\dotnet\sdk\2.1.400\sdk\Microsoft.NET.sdk\targets\Microsoft.NET.RuntimeIdentifierReference.targets(122,5):错误NETSDK1067:使用应用程序主机需要自包含的应用程序。将SelfContained设置为false或将UseAppHost设置为true。[C:\Users\Guillem.Sola\source\repos\ASG.DHW.HealthCheck\ASG.DHW.HealthCheck.API\ASG.DHW.HealthCheck.API.csproj]

我可以在cmd中实现类似的执行

dotnet发布。\HealthCheck.API\HealthCheck.API.csproj-o。\bin\publish-r win-x64-c发布


发生了什么,为什么从CLI调用时配置文件的行为不一样?

我认为(更新)问题的关键可能在错误消息的这一部分:

使用应用程序主机需要自包含的应用程序。将SelfContained设置为false或将UseAppHost设置为true

行为上的差异可以很容易地用很多东西来解释,例如,由各种VS条件引入的MSBuild目标文件

因为您不想使用AppHost,所以需要将
true
更改为
false
。您还可以考虑添加一个显式<代码> false <代码>,这可能有助于减轻VS和CI构建之间的差异。
打开/打开MSBuild详细信息是获取更多数据的好方法,可以帮助您理解操作为何会有观察到的结果。

如果您有一段时间没有更新.net core sdk,这可能适用:@JoshE根据您的建议,我已更新了VS(它在1个月前更新过),现在在控制台上执行时出现错误。添加更多细节的问题,我明白了,顺便说一句,自我包含是我想要的东西,因为我不打算在机器上安装fw。那么,您的意思是从控制台调用配置文件的行为完全不同吗:O恐怕我需要打开详细日志XD谢谢!设置
--self-contained=false
解决了该问题。现在VS和
dotnet publish…
cmd的结果是一样的!上帝,谢谢!