我正在尝试使用特定的发布配置文件 pubxml 文件调用“dotnetpublish”,如此处记录的:
但是,我尝试的所有操作似乎都会导致默认行为,并且 /p:PublishProfile 部分被忽略。
dotnet publish /p:PublishProfile="MyFolderProfile"
不起作用,并且没有记录任何错误,构建到“/obj”下的默认位置。
我确实注意到,故意错误的命令会产生相同的结果,例如:
dotnet publish /p:PublishProfile="MyFolderProfile-XXXXX"
我做错了什么? - 任何指示将不胜感激!
我的回复迟了。我的解决方案有一个简单的 .NET Core 控制台应用程序
ConsoleAppCore.csproj
。我使用 Visual Studio IDE
生成了一个名为 FolderProfile.pubxml
的发布配置文件,然后以下命令对我有用:
相对路径 - 从解决方案根开始
dotnet publish ConsoleAppCore\ConsoleAppCore.csproj /p:PublishProfile=ConsoleAppCore\Properties\PublishProfiles\FolderProfile.pubxml
绝对路径 - 从任何位置
dotnet publish "C:\work\ConsoleAppCore\ConsoleAppCore.csproj" "/p:PublishProfile=C:\work\ConsoleAppCore\Properties\PublishProfiles\FolderProfile.pubxml"
在 Azure 开发运营上
任务名称=.NET Core
任务版本=2
命令=发布
项目路径=我将其留空
参数=
$(System.DefaultWorkingDirectory)\ConsoleAppCore\ConsoleAppCore.csproj /p:PublishProfile=$(System.DefaultWorkingDirectory)\ConsoleAppCore\Properties\PublishProfiles\FolderProfile.pubxml --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)\ConsoleAppCore-Publish\
在 Azure Dev Ops 构建管道场景中,我已将输出重定向到
$(Build.ArtifactStagingDirectory)
下的文件夹。我还有一个 Publish Artifact 任务,该任务配置为使用暂存目录变量。
我使用了发布配置文件 XML 文件,因为我想要一个文件来管理 Azure Devops 上的完整行为。所有参数依靠单个文件简化了 Azure 上的管理。
Azure Dev ops - Artifacts Explorer
Publish Artifact
任务为我创建了一个drop,这就是它的样子。请注意,资源管理器中的文件名与 --output
任务中的 dotnet publish
选项指定的名称一致
我不久前遇到了同样的问题。我设法通过调用来修复它:
dotnet build [projectname] /p:PublishProfile=[PublishProfile]
文件夹发布存在一个未解决的(截至 2021 年 10 月)问题,具有类似的症状 https://github.com/dotnet/sdk/issues/12490
我现在使用的解决方法是手动编辑 VS.Net 生成的
*.pubxml
文件,使 PublishUrl
和 PublishDir
键具有相同的值。
这样
dotnet publish -p:PublishProfile=...
就可以按预期工作了。
您可能需要完整路径,例如
dotnet publish -c Release /p:PublishProfile=Properties\PublishProfiles\FolderProfile.pubxml
dotnet build ..\project\project.csproj /p:DeployOnBuild=true -c Release /p:PublishProfile="Folder Staging"
我添加了相对 csproj 路径和带有空格的发布配置文件名称,以阐明如何处理这些情况。
-c
标志可选地用于指定要使用的配置。
请参阅https://github.com/dotnet/docs/issues/19677。 PublishProfile 只是名称,其之前的任何目录都将被忽略。
PublishProfile 属性被视为文件名,目录为 单独建造。
如果指定自定义路径,则应使用
PublishProfileFullPath
属性。
要解决该问题,您必须将 < PublishDir > 属性添加到 .pubxml 文件中。然后
dotnet publish /p:Configuration=Release /p:PublishProfile=FolderProfile
命令运行良好。
以下示例。
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>false</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>C:\MyApp\PUBLISH</PublishUrl>
<PublishDir>C:\MyApp\PUBLISH</PublishDir>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
</PropertyGroup>
</Project>
您还可以使用相对路径,例如
<PublishUrl>PUBLISH</PublishUrl>
<PublishDir>PUBLISH</PublishDir>
我在 VS 构建事件中使用了这个
dotnet publish $(SolutionDir)DIRECTORI_1/PROJECT_1.csproj -c Release -o C:\Deployments\FOLDER_1
假设您想从命令行发布多个项目,并让它的行为就像您在 GUI 中按下发布按钮(一个接一个)一样。我必须从多个答案中拼凑出解决方案。许多人都有解决方案的关键部分,但没有人把它全部放在一起。
PublishDir
和PublishUrl
,因为一个由GUI中的发布按钮使用,另一个由命令行工具使用。FolderProfile.pubxml
<PublishDir>Publish</PublishDir>
<PublishUrl>Publish</PublishUrl>
您无法使用
dotnet publish
,它现在刚刚损坏,并且该问题在本帖子中已开放 4 年多了。请使用 dotnet.exe build
,当传递发布配置文件时,它将构建然后发布,就像 GUI 中的按钮一样。
用户@shlgug 和@A.Don 在这里最接近,但您必须用分号连接参数。如果您尝试传递多个
-p
或 /p
参数,它将失败并显示 MSB1001: Unknown switch
这是一组对我有用的属性示例:
dotnet.exe build "path\to\project.csproj" -property:Configuration=Release;PublishProfile="FolderProfile";DeployOnBuild=True -target:Publish
正在与:
Microsoft (R) .NET SDK version 8.0.400
合作