pan*_*nis 3 .net c# asp.net msbuild .net-core
我有以下通过 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>
Run Code Online (Sandbox Code Playgroud)
当我运行dotnet.exe publish src\MyProject.Web.sln -p:PublishProfile=Properties\PublishProfiles\ProductionPublish.pubxmlRelease 不包含任何内容并且发布发生在 Debug 文件夹(调试版本)上。为什么会发生这种情况并且忽略 pubxml?
更新 #1
Structure
src\MyProject\MyProject.csproj
src\MyProject.Utils\ect.Utils.csproj
src\MyProject.Web\MyProject.Web.csproj
src\MyProject.Web.sln
Run Code Online (Sandbox Code Playgroud)
和 pubxml 的路径
src\MyProject.Web\Properties\PublishProfiles\ProductionPublish.pubxml
Run Code Online (Sandbox Code Playgroud)
pal*_*rom 11
您需要使用以下命令:
dotnet build -c Release /p:DeployOnBuild=true /p:PublishProfile=FolderProfile
Run Code Online (Sandbox Code Playgroud)
是build,不是publish。
即使我的 FolderProfile 的配置设置为 Release,我也必须包括在内,-c Release因为否则依赖项目是使用调试配置构建的。
如果没有调用文件,则不会将文件复制到目标位置/p:DeployOnBuild=true。
FolderProfile对于
配置文件,仅名称(不带扩展名)就足够了。或者你可以给路径
/p:PublishProfile=Properties\PublishProfiles\FolderProfile.pubxml
请参阅Microsoft Docs 中的文件夹发布示例。
在VS2022和Core 6上找到了一个解决方案,可以发布到特定文件夹,而无需在CLI上指示输出路径。
我创建了一个名为 IISC 的配置文件
如果您打开该发布配置文件,您将看到 PublishUrl 属性,如下所示
<PublishUrl>bin\Release\net6.0\publish\IISC</PublishUrl>
Run Code Online (Sandbox Code Playgroud)
在我的例子中,我发布到解决方案文件夹 bin\releas....\IISC
诀窍是添加另一个名为 PublishDir 的属性
<PublishDir>bin\Release\net6.0\publish\IISC</PublishDir>
Run Code Online (Sandbox Code Playgroud)
现在您可以使用以下命令进行发布:
dotnet publish -c Release /p:PublishProfile=IISC
Run Code Online (Sandbox Code Playgroud)
查找下面的“我的完整配置文件”,并添加特定于此配置文件的环境变量和项目组,以排除除 appsettings.json 和 appsettings.IISC.json 之外的所有 appsettings
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<ASPNETCORE_ENVIRONMENT>iisc</ASPNETCORE_ENVIRONMENT>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net6.0\publish\IISC</PublishUrl>
<PublishDir>bin\Release\net6.0\publish\IISC</PublishDir>
<WebPublishMethod>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net6.0</TargetFramework>
<ProjectGuid>3e4c25a6-2051-4ccc-a518-645d46d120dd</ProjectGuid>
<SelfContained>false</SelfContained>
</PropertyGroup>
<ItemGroup>
<Content Update="appsettings.*.json">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
<Content Update="appsettings.$(ASPNETCORE_ENVIRONMENT).json">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1585 次 |
| 最近记录: |