【问题标题】:dotnet publish profile ignores pubxml filedotnet 发布配置文件忽略 pubxml 文件
【发布时间】:2020-10-28 10:18:00
【问题描述】:

我有以下通过 Visual Studio 2019 创建的 pubxml 文件:

<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>netcoreapp3.1</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <ProjectGuid>143a6329-27d9-474e-9521-835be634c293</ProjectGuid>
    <SelfContained>true</SelfContained>
    <publishUrl>bin\Release\netcoreapp3.1\publish\</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

当我运行 dotnet.exe publish src\MyProject.Web.sln -p:PublishProfile=Properties\PublishProfiles\ProductionPublish.pubxml 时,Release 不包含任何内容,并且发布发生在 Debug 文件夹(调试构建)上。为什么会发生这种情况并且 pubxml 被忽略?

更新 #1

Structure
src\MyProject\MyProject.csproj
src\MyProject.Utils\ect.Utils.csproj
src\MyProject.Web\MyProject.Web.csproj
src\MyProject.Web.sln

以及 pubxml 的路径

src\MyProject.Web\Properties\PublishProfiles\ProductionPublish.pubxml

【问题讨论】:

  • 你有解决方案下的属性文件夹吗?还是在解决方案中的一个项目下?
  • 更新了我的帖子请查收
  • 您正在尝试发布解决方案。您应该从 MyProject.Web 文件夹运行 dotnet publish 命令。这将发布您可以部署到 Web 服务器的 Web 应用程序。从 Web 项目文件夹运行时,您不需要将 src\MyProject.Web.sln 参数传递给 dotnet publish 命令。
  • 我切换到你说的dotnet.exe publish Radius.MicroServices.CySec.Web.csproj -p:PublishProfile=Properties\PublishProfiles\ProductionPublish.pubxml,结果还是一样

标签: c# asp.net .net .net-core msbuild


【解决方案1】:

您需要使用以下命令:

dotnet build -c Release /p:DeployOnBuild=true /p:PublishProfile=FolderProfile
  • 这是build,而不是publish

  • 即使我的 FolderProfile 的配置设置为 Release,我也必须 包括-c Release,因为否则会构建依赖项目 带有调试配置。

  • 如果在没有/p:DeployOnBuild=true 的情况下调用,文件不会复制到目标位置。

  • 只需名称FolderProfile - 不带扩展名- 就足够了
    配置文件。或者你可以给路径
    /p:PublishProfile=Properties\PublishProfiles\FolderProfile.pubxml

请参阅 Microsoft Docs 中的 Folder publish example

【讨论】:

  • 这是唯一对我有用的解决方案。我想通过“dotnet publish”使用发布配置文件,并将配置文件作为参数传递,但它从未起作用。这解决了我的问题,谢谢!
  • 确实谢谢。 dotnet publish 在 net5 中没问题,但升级到 net6 后,它不再对我有用。这是唯一对我有用的命令
【解决方案2】:

我将为像我一样确实想要使用 publish 命令的人回答,因为它的设计初衷就是这样做的。

根据 publish 命令的Options 部分,您可以使用选项 configurationoutput 来解决您的问题:

dotnet publish -c Release -o "<where you want>" -p:PublishProfile=<your profile name>

请注意,您想要的位置可以是绝对路径,您的个人资料名称只是个人资料的名称,没有“pubxml”,也没有相对路径(IF AND仅当配置文件位于“/Properties/PublishProfiles”中时)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    相关资源
    最近更新 更多