-1

Similar questions here and here didn't work in my case. The xcopy commands I use in Post Build per project won't work in Azure pipelines and build fails. Without getting this done, i can't publish to staging. So basically I am stuck.

My source structure is shown in below screen shot;

Project Structure

As you see the plugin projects are inside /Modules folder. In VS I have post build xcopy commands in every plugin project inside /Modules to copy required files (like wwwroot, views etc..) to Host projects /Modules folder. So in VS once everything is completed and deployed; folder structure will look like below;

Final folder structure

Here you see that plugin data gets copied to [Modules] folder inside host project. Those will be copied as \Modules[plugin name]....

However in Azure this xcopy doesn't work and I cant get the copy file task to work properly. Basically there should be something which will get this done locally as well as azure pipelines without having to maintain two things (for local & pipelines)?

UPDATE-1 I removed xcopy task and tried to do everything using MSBuild copy tasks. So, the projects that require their files to be copied to host project has below in .csproj file.

<PropertyGroup>
  <SolutionDirectory>$([MSBuild]::GetDirectoryNameOfFileAbove(`$(MSBuildProjectDirectory)`, `Main.Project.sln`))\</SolutionDirectory>
 <PluginDirectory>$([System.IO.Path]::GetFullPath('$(SolutionDirectory)\Host.Project\Modules\$(MSBuildProjectName)'))</PluginDirectory>
</PropertyGroup>
<ItemGroup>
<ViewFiles Include="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\Views'))\**\*.*"></ViewFiles>
<WWWRootFiles Include="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\wwwroot'))\**\*.*"></WWWRootFiles>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy
  SourceFiles="@(ViewFiles)"
  DestinationFolder="$(PluginDirectory)\Views\%(RecursiveDir)"
  SkipUnchangedFiles="true"/>

<Copy
  SourceFiles="@(WWWRootFiles)"
  DestinationFolder="$(PluginDirectory)\wwwroot\%(RecursiveDir)"
  SkipUnchangedFiles="true"/>
</Target>

Now this does the same thing as Xcopy did earlier. This does not give errors in Azure pipeline when building. but files are not being copied either.

  1. Is there a way to kind of debug/troubleshoot these commands in Azure pipeline?

  2. Since i am using MSBuild tasks to do the copying without using Pipeline tasks (exL- Copy file task), may be Azure pipelines doesn't support MSBuild tasks?

user2058413
  • 691
  • 3
  • 10
  • 28
  • Yeah so some details are missing. WHY is the xcopy not working in the pipeline, and WHY are you unable to get the file task to work. How are you expecting us to answer this question without more details. I'm not even sure what the question is – PaulVrugt May 28 '21 at 18:06
  • Well short answer is, xcopy doesn't seem to be supported in Auzre pipelines. Anyway then i removed xcopy and used MSBuild tasks to do the same, now no build errors. I have updated the question above with more details about where I am now. – user2058413 May 29 '21 at 05:18
  • You can increase the verbosity of the log while building to see what's happening. You could also just use copy instead of xcopy – PaulVrugt May 30 '21 at 06:04
  • Did you use your private agent? And the copied file are not under repos but under the agent workspace directory. You could use `system.debug=true` to check the detailed log. And if you use private agent, please enter the agent's `_work` folder to get that. If you use hosted agent to run the pipeline, you should add `Publish build artifacts` task with `$(Build.SourcesDirectory)` to get see the changes. See [this issue](https://stackoverflow.com/questions/67500480/not-able-to-publish-the-test-results-from-newman-during-postman-integration-with/67515714#67515714). – Mr Qian May 31 '21 at 09:06
  • @user2058413, please check if my answer gets the key. – Mr Qian May 31 '21 at 09:19

1 Answers1

0

Use system.debug=true variable under azure pipeline to see the detailed log.

Also, msbuild property functions cannot be nested into a second level item or property.

So you should change your csproj file to:

<PropertyGroup>
  <SolutionDirectory>$([MSBuild]::GetDirectoryNameOfFileAbove(`$(MSBuildProjectDirectory)`, `Main.Project.sln`))\</SolutionDirectory>
 <PluginDirectory>$([System.IO.Path]::GetFullPath('$(SolutionDirectory)\Host.Project\Modules\$(MSBuildProjectName)'))</PluginDirectory>

<View_PluginDirectory>$([System.IO.Path]::GetFullPath('$(SolutionDirectory)\Host.Project\Modules\$(MSBuildProjectName)'))\Views\%(RecursiveDir)</View_PluginDirectory>

<wwwroot_PluginDirectory>$([System.IO.Path]::GetFullPath('$(SolutionDirectory)\Host.Project\Modules\$(MSBuildProjectName)'))\wwwroot\%(RecursiveDir)</wwwroot_PluginDirectory>


</PropertyGroup>
<ItemGroup>
<ViewFiles Include="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\Views'))\**\*.*"></ViewFiles>


<WWWRootFiles Include="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\wwwroot'))\**\*.*"></WWWRootFiles>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy
  SourceFiles="@(ViewFiles)"
  DestinationFolder="$(View_PluginDirectory)"
  SkipUnchangedFiles="true"/>

<Copy
  SourceFiles="@(WWWRootFiles)"
  DestinationFolder="$(wwwroot_PluginDirectory)"
  SkipUnchangedFiles="true"/>
</Target>
Mr Qian
  • 21,064
  • 1
  • 31
  • 41