我需要从Web Deploy发布中排除与数据库相关的设置.我试图删除pubxml文件中的部分,但是当我创建部署包时它会回来.
有没有办法从Web Deploy发布中排除数据库相关设置?
在Visual Studio 2017中,使用文件系统发布方法发布Asp.Net Core网站时,我想.bat在发布操作将文件复制到输出目录后触发文件执行。
我了解到,Visual Studio将发布操作的设置存储在项目Properties/PublishProviles目录的.pubxml文件中。因此,在某些情况下,文件可能是FolderProfile.pubxml,并且当前看起来像这样:
<?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>False</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>net461</PublishFramework>
<ProjectGuid>f58b5ca0-8221-4c97-aa6d-7fba93a3abeb</ProjectGuid>
<publishUrl>C:\inetpub\wwwGiftOasisResponsivePublished</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
根据.pubxml文件中的注释和其他研究,据我了解,此文件实质上是msbuild文件,最终使用msbuild来执行发布操作。msbuild文件看起来非常灵活,但是有点复杂。我真的很努力与此。
如果我的项目根目录中有一个批处理文件,名为finishPub.bat,在将网站复制到输出文件夹后,如何修改上述.pubxml …
我试图在 ASP.NET 文件系统发布中包含一个未包含在解决方案中的文件(它是从构建后脚本自动生成的)。根据这些说明,我应该能够.pubxml使用<_CustomFiles>元素在我的定义中添加对文件的引用。这是我的.pubxml文件的样子:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>(publish URL here)</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="scripts\app.min.js" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
第二个<PropertyGroup>和<Target>元素是我添加的。
但是,Visual Studio 无法识别该<_CustomFiles>元素,并且该文件未包含在发布中。注意元素下方的绿色波浪线:

当我将鼠标悬停在它上面时,会显示以下错误消息:
The element 'ItemGroup' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element '_CustomFiles' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'
Run Code Online (Sandbox Code Playgroud)
为什么 Visual Studio …
我有一个用于构建和发布 cs 项目的 YAML 管道。我尝试将预定义变量放入发布配置文件中,但它引发了错误。我希望将已发布的文件放入该$(Build.ArtifactStagingDirectory)位置,以便我可以使用“发布构建工件”任务。
我不确定为什么当在代理目录中运行时,发布配置文件中的变量无法按预期工作。
错误:
错误 MSB4184:无法计算表达式“””.ArtifactStagingDirectory”。未找到方法“System.String.ArtifactStagingDirectory”
yaml:
- task: MSBuild@1
displayName: '${{ parameters.Site }} - Publish'
inputs:
solution: '*${{ parameters.Location }}/${{ parameters.Site }}.csproj'
msbuildVersion: '15.0'
msbuildArchitecture: 'x64'
platform: 'anycpu'
configuration: '${{ parameters.Configuration }}'
msbuildArguments: '/p:PublishProfile=$(Build.SourcesDirectory)\${{ parameters.Location }}\Properties\PublishProfiles\STARS.Website.Publish.Profile.pubxml'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: '${{ parameters.Site }}'
Run Code Online (Sandbox Code Playgroud)
pubxml:
<?xml version="1.0" encoding="utf-8"?>
<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>True</ExcludeApp_Data>
<publishUrl>$(Build.ArtifactStagingDirectory)</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud) 我们有一个包含多个项目的 ASP.Net 解决方案。每个项目都有build.pubxml唯一的文件夹路径。
例如:
在项目中,Test我们在以下内容中有这一行build.pubxml:
<publishUrl>C:\publish\SolutionName\Test</publishUrl>
Run Code Online (Sandbox Code Playgroud)
在项目中,Exam我们在以下内容中有这一行build.pubxml:
<publishUrl>C:\publish\SolutionName\Exam</publishUrl>
Run Code Online (Sandbox Code Playgroud)
在构建管道(在 TFS 中)中,MSBuild 步骤带有此参数:
/p:PublishProfile=build.pubxml
Run Code Online (Sandbox Code Playgroud)
构建完成后,我们得到了 2 个文件夹-Test以及.ExamC:\publish\SolutionName
到目前为止,一切都很好。
问题是我们的分支很少,并且我们希望将每个分支的发布文件夹分开,因此我们.pubxml为每个分支添加了内容,并在构建管道中指定了正确的分支。但是 make 在创建的每个新分支上都需要大量工作,并且可能会导致错误。
我们尝试在 MSBuild 中传递/p:publishUrl=C:\publish\BranchName,但随后我们得到了一个文件夹,其中包含 和 的所有内容Test,Exam而不是两个文件夹。
这个想法是每个项目只有一个 .pubxml带有参数的文件,并在管道中传递值,例如:
<publishUrl>C:\publish\$(Parameter)\Test</publishUrl>
Run Code Online (Sandbox Code Playgroud)
并且在构建中我们将根据分支传递参数。
有可能做这样的事情吗?
pubxml ×5
msbuild ×3
asp.net ×2
asp.net-mvc ×1
azure-devops ×1
csproj ×1
publish ×1
publishing ×1
tfs ×1
yaml ×1