简体   繁体   English

VSTS构建似乎没有将输出文件发布到正确的目录

[英]VSTS build does not seem to publish output files to proper directory

I am developing an ASP.NET core application. 我正在开发一个ASP.NET核心应用程序。

I use VSTS online for my source control. 我将VSTS在线用于源代码控制。 I also have a dedicated machine to build the application. 我也有专用的机器来构建应用程序。

To automate the process, I am now trying to define a build script from VSTS online. 为了自动化该过程,我现在尝试从VSTS在线定义一个构建脚本。

The default VSTS template defines many tasks. 默认的VSTS模板定义了许多任务。 I removed all the unneeded tasks for my purpose and am down to just three tasks - "Use NuGet," "NuGet Restore," and "Build Solution." 我删除了所有我不需要的任务,只剩下三个任务-“使用NuGet”,“ NuGet恢复”和“构建解决方案”。

The default msbuild argument for "Build Solution" task is: “构建解决方案”任务的默认msbuild参数为:

/p:DeployOnBuild=true /p:WebPublishMethod=Package 
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true 
/p:DesktopBuildPackageLocation=
   "$(build.artifactstagingdirectory)\WebApp.zip" 
/p:DeployIisAppPath="Default Web Site"

Although there is no error in running this script, I need to change it such that the output goes to a folder and is not packaged. 尽管运行该脚本没有错误,但是我需要对其进行更改,以使输出转到文件夹中且未打包。

Here is part of my directory structure that is relevant for my question: 这是与我的问题相关的目录结构的一部分:

C:\Dev\RCWebsite\RCWebsite.sln
C:\Dev\RCWebsite\RCWeb\RCWeb.csproj
C:\Dev\RCWebsite\RCWeb\Properties\PublishProfiles\FolderProfile.pubxml

Here is the content of the publish profile: 这是发布配置文件的内容:

<PropertyGroup>
  <WebPublishMethod>FileSystem</WebPublishMethod>
  <PublishProvider>FileSystem</PublishProvider>
  <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
  <LastUsedPlatform>Any CPU</LastUsedPlatform>
  <SiteUrlToLaunchAfterPublish />
  <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
  <ExcludeApp_Data>False</ExcludeApp_Data>
  <ProjectGuid>d7d9f3b7-fd0e-49c1-b6d2-3af5dddb6699</ProjectGuid>
  <publishUrl>C:\StagingSites\rcweb</publishUrl>
  <DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>

From the console window, I can run the following command: 在控制台窗口中,我可以运行以下命令:

msbuild .\RCWeb\RCWeb.csproj /p:DeployOnBuild=true 
 /p:PublishProfile=RCWeb\Properties\PublishProfiles\FolderProfile.pubxml

This works as expected. 这按预期工作。 The final output is generated in C:\\StagingSites\\rcweb\\ directory. 最终输出在C:\\StagingSites\\rcweb\\目录中生成。

As this command works, I replaced the msbuild argument in VSTS "Build Solution" task as: 由于此命令有效,我将VSTS“构建解决方案”任务中的msbuild参数替换为:

/p:DeployOnBuild=true 
 /p:PublishProfile=rcWeb\Properties\PublishProfiles\FolderProfile.pubxml

Note that I haven't specified .\\RCWeb\\RCWeb.csproj as an argument. 请注意,我没有指定.\\RCWeb\\RCWeb.csproj作为参数。 Guess the build mechanism automatically takes care of this. 猜猜构建机制会自动解决这一问题。

When I run this build and look at the log file, I see that the solution is built fine. 当我运行此构建并查看日志文件时,我看到该解决方案构建良好。 However, it is never copied to C:\\StagingSites\\rcweb\\ directory. 但是,它永远不会复制到C:\\StagingSites\\rcweb\\目录。

Can someone please tell me what is it that I am missing? 有人可以告诉我我想念的是什么吗? Do I need another "deployment" task after "build solution" task? 在“构建解决方案”任务之后,我是否需要另一个“部署”任务? Regards. 问候。

Although there is no error in running this script, I need to change it such that the output goes to a folder and is not packaged. 尽管运行该脚本没有错误,但是我需要对其进行更改,以使输出转到文件夹中且未打包。

No you do not need another deployment task. 不,您不需要其他部署任务。 Since you do not need to package and deploy the ASP .NET project with msbuild, you can get rid of the /p:DeployOnBuild=true flag to msbuild. 由于不需要使用msbuild打包和部署ASP .NET项目,因此可以摆脱/p:DeployOnBuild=true标记的msbuild。 Also, after having a look at your publish profile I realized that you aren't really passing any information to msbuild (nothing that can't be passed from msbuild parameters atleast) and since you no longer plan to directly deploy from msbuild, it would be a good idea to keep the publish profile aside. 另外,在查看了您的发布配置文件之后,我意识到您并没有真正将任何信息传递给msbuild(至少不能从msbuild参数传递任何信息),并且由于您不再打算直接从msbuild进行部署,因此保留发布个人资料是一个好主意。

After trimming down the parameters and adding a few necessary ones ( /T:Package tells msbuild that you want to package the binaries but not deploy them), this is what your msbuild command would look like: 减少参数并添加一些必要的参数后( /T:Package告诉msbuild您想打包二进制文件但不部署它们),这就是msbuild命令的样子:

/p:OutDir=$(Build.BinariesDirectory) /T:Package /p:PackageLocation=$(Build.BinariesDirectory)\WebApp.zip   /p:PackageAsSingleFile=true

This is assuming that you wish to have a .zip file that is ready to be deployed, as the output. 假设您希望拥有一个准备好部署的.zip文件作为输出。 If that's not the case and you just require the binaries in a folder that can be directly deployed but not zipped, you can use the below command: 如果不是这种情况,而您只需要将二进制文件放在可以直接部署但不能压缩的文件夹中,则可以使用以下命令:

/p:OutDir=$(Build.BinariesDirectory) /T:Package /p:PackageLocation=$(Build.BinariesDirectory)\WebApp.zip  /p:PackageAsSingleFile=true p:_PackageTempDir=$(Build.BinariesDirectory)\MyAspNetWebsite

This will generate the zip as well as the binaries folder ready to be deployed (sadly you need the zip for the temporary dir flag to work) 这将生成zip以及准备部署的Binaries文件夹(不幸的是,您需要zip才能使临时dir标志起作用)

NOTE: If you plan on using the msbuild command within a powershell script, the VSO variables will need to accessed in a different way, like so: 'BUILD_BINARIESDIRECTORY' 注意:如果计划在Powershell脚本中使用msbuild命令,则需要以其他方式访问VSO变量,例如: 'BUILD_BINARIESDIRECTORY'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM