带MsBuild的xcopy

带MsBuild的xcopy,msbuild,xcopy,msbuild-4.0,Msbuild,Xcopy,Msbuild 4.0,我有一个非常简单的构建脚本,如下所示: <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Bundle"> <ItemGroup> <BuildArtifacts Include="..\_buildartifacts" /> <Application Include="..

我有一个非常简单的构建脚本,如下所示:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Bundle">

<ItemGroup>
    <BuildArtifacts Include="..\_buildartifacts" />
    <Application    Include="..\_application" />
</ItemGroup>

<Target Name="Clean">
    <RemoveDir Directories="@(BuildArtifacts)" />
    <RemoveDir Directories="@(Application)" />
</Target>

<Target Name="Init" DependsOnTargets="Clean">
    <MakeDir Directories="@(BuildArtifacts)" />
    <MakeDir Directories="@(Application)" />
</Target>

<Target Name="Bundle" DependsOnTargets="Compile">
    <Exec Command="xcopy.exe %(BuildArtifacts.FullPath) %(Application.FullPath) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" WorkingDirectory="C:\Windows\" />
</Target>

现在它开始工作了:)

您需要执行两次xcopy。您试图在同一调用中对两个不同的项数组使用任务批处理,但实际情况并非如此。试试这个:

<Target Name="Bundle" DependsOnTargets="Compile">
  <Exec Command="xcopy.exe %(BuildArtifacts.FullPath) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" WorkingDirectory="C:\Windows\" />
  <Exec Command="xcopy.exe %(Application.FullPath) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" WorkingDirectory="C:\Windows\" />
</Target>

我设法解决了这个问题。我已经用解决方案更新了这个问题

我删除了最后一部分WorkingDirectory=“C:\Windows\”并将脚本更改为:

<Exec Command="xcopy.exe @(BuildArtifacts) @(Application) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" />
 <Exec Command="xcopy.exe @(BuildArtifacts) @(Application) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" />


现在它开始工作了:)

使用内置的
任务而不是
xcopy
调用:嗯,我无法让它工作,xcopy需要一个目标路径,这就是%(Application.FullPath)应该是什么。我不确定我是否完全理解MSBuild语法