简体   繁体   中英

VSTS build does not seem to publish output files to proper directory

I am developing an ASP.NET core application.

I use VSTS online for my source control. 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.

The default VSTS template defines many tasks. I removed all the unneeded tasks for my purpose and am down to just three tasks - "Use NuGet," "NuGet Restore," and "Build Solution."

The default msbuild argument for "Build Solution" task is:

/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.

As this command works, I replaced the msbuild argument in VSTS "Build Solution" task as:

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

Note that I haven't specified .\\RCWeb\\RCWeb.csproj as an argument. 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.

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. 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.

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:

/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. 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)

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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