Bin folder not being copied with MSBuild, Teamcity

筅森魡賤 提交于 2019-12-19 08:28:19

问题


I have a very odd issue, where I've created a custom MSBuild task that would move all files I need for my MVC project to a specific location so that we can publish it. This works fine when I trigger the script localy on my machine but as soon as I check this changes in and Teamcity runs the script, it copies everything except from the Bin folder. However, if run MSbuild directlly from the command line (same script), it does copy the bin folder. I don't understand why this isn't working when TeamCity is building it.

Does anyone have an idea why this is happening and how to solve it?

<Target Name="AfterBuild">
   <CallTarget Targets="Move" />
</Target>
<Target Name="Move">
    <Copy SourceFiles="@(BinFolder)" DestinationFolder="$(ArtifactsDir)\Webproject.Web\bin" />
    <Copy SourceFiles="@(ContentFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Content" />
    <Copy SourceFiles="@(ImagesFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Images" />
    <Copy SourceFiles="@(ScriptsFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Scripts" />
</Target>


<ItemGroup>
   <BinFolder Exclude="*.cs" Include="$(ProjectDir)bin\**\*.*"/>
   <ContentFolder Exclude="*.cs;*.svn-base" Include="$(ProjectDir)Content\*.css"/>
   <ImagesFolder Exclude="*.cs;*.svn-base" Include="$(ProjectDir)Images\*.*"/>
   <ScriptsFolder Exclude="*.cs;*.svn-base" Include="$(ProjectDir)Scripts\*.js"/>
</ItemGroup>

$(ArtifactsDir) is a paramanter I'm passing in from Teamcity & manually in the command line.

/p:ArtifactsDir="%system.agent.work.dir%\WebProject\trunk\Website"

回答1:


I think it's a problem of items evaluation. Your "BinFolder" item is interpreted at the first time MsBuild read your build file, i.e. before the build. And I think that $(ProjectDir)bin***.* is empty before the build. To avoid this you can declare your binfolder within your target as shown :

<Target Name="AfterBuild">
   <CallTarget Targets="Move" />
</Target>
<Target Name="Move">

    <ItemGroup>
      <BinFolder Exclude="*.cs" Include="$(ProjectDir)bin\**\*.*"/>
    </ItemGroup>

    <Copy SourceFiles="@(BinFolder)" DestinationFolder="$(ArtifactsDir)\Webproject.Web\bin" />
    <Copy SourceFiles="@(ContentFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Content" />
    <Copy SourceFiles="@(ImagesFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Images" />
    <Copy SourceFiles="@(ScriptsFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Scripts" />
</Target>

<ItemGroup>
   <ContentFolder Exclude="*.cs;*.svn-base" Include="$(ProjectDir)Content\*.css"/>
   <ImagesFolder Exclude="*.cs;*.svn-base" Include="$(ProjectDir)Images\*.*"/>
   <ScriptsFolder Exclude="*.cs;*.svn-base" Include="$(ProjectDir)Scripts\*.js"/>
</ItemGroup>

Or else you could try using CreateItem task :

<Target Name="Move">

    <CreateItem Exclude="*.cs" Include="$(ProjectDir)bin\**\*.*">
      <Output TaskParameter="Include" ItemName="TheFiles"/>
    </CreateItem>

    <Copy SourceFiles="@(BinFolder)" DestinationFolder="$(ArtifactsDir)\Webproject.Web\bin" />
    <Copy SourceFiles="@(ContentFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Content" />
    <Copy SourceFiles="@(ImagesFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Images" />
    <Copy SourceFiles="@(ScriptsFolder)" DestinationFolder="$(ArtifactsDir)\SchrodersFundEngine.Web\Scripts" />
</Target>

You can find more information here :

  • MSBuild ItemGroup Include/Exclude pattern issue
  • http://blogs.msdn.com/b/msbuild/archive/2006/01/03/508629.aspx
  • http://www.sedodream.com/PermaLink,guid,dd6cb1db-c0e4-47f7-ad84-6e59ff6b03d0.aspx


来源:https://stackoverflow.com/questions/3943136/bin-folder-not-being-copied-with-msbuild-teamcity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!