Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, The problem I face is my target 'CopyBuildFiles' does not copy as I think it is unable to find the build folder. The build folder is defined in the property $(BuildFolder), this folder name is created based on date.time and is created in one of the previous targets that runs before 'CopyBuildFiles'.
If I hardcode a path for @(SrcFiles) instead of deriving this from $(BuildFolder) it works.
Any thoughts, what is happening here and how can this be resolved?
Many thanks.

XML
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <year>$([System.DateTime]::Now.ToString("yy"))</year>
        <month>$([System.DateTime]::Now.ToString("MM"))</month>
        <day>$([System.DateTime]::Now.ToString("dd"))</day>
        <time>$([System.DateTime]::Now.ToString("HHmm"))</time>
        <AssemblyFileVersionAttribute>[$(year).$(month).$(day).$(time))]      </AssemblyFileVersionAttribute>
        <BuildFolder>c:\website.builds\$(AssemblyFileVersionAttribute)\</BuildFolder>
        <IISFolder>c:\website.publish\</IISFolder>        
        <LogDirectory>C:\website.builds.logs</LogDirectory>
        <LogFile>C:\website.builds.logs\Buildlog_$(AssemblyFileVersionAttribute).txt</LogFile>
        
    </PropertyGroup>
    
   
    <Target Name="PreBuild">
        <MakeDir Directories="$(LogDirectory)" />       
        <RemoveDir Directories="$(IISFolder)"></RemoveDir>        
        <MakeDir Directories="$(BuildFolder)" />
        <MakeDir Directories="$(IISFolder)" />        
    </Target>
    <Target Name="Compile">
        <MSBuild Projects="$(MSBuildStartupDirectory)\websitev2.sln"  Properties="OutDir=$(BuildFolder)\" />        
    </Target>
    <ItemGroup>
        <SrcFiles Include="$(BuildFolder)_PublishedWebsites\**\*.*"/>
    </ItemGroup>
    <Target Name="CopyBuildFiles"
              Inputs="@(SrcFiles)"
              Outputs=
          "@(SrcFiles->'$(IISFolder)%(RecursiveDir)%(Filename)%(Extension)')">
        <Copy SourceFiles="@(SrcFiles)"
              DestinationFiles="@(SrcFiles->'$(IISFolder)%(RecursiveDir)%(Filename)%(Extension)')"
          />      
    </Target>
    
    <Target Name="Deploy">
        <CallTarget Targets="PreBuild" />
        <CallTarget Targets="Compile" />
        <CallTarget Targets="CopyBuildFiles" />
    </Target>
   
</Project>
Posted

Sorry if my post does not help you as you expect.

I just don't think I have enough patience to find a "lost" folder for your. I used to do way more sophisticated master projects with special targets, but this is possible when you have everything in your hands and can debug the process (which itself requires you to be very methodical), but after all, this is nothing more than understanding how build works and basic string and set manipulations. Come one, you can do it.

I would rather tell you about different things. Instead of ramming your problem, try to think: what are your doing?!

Do you understand that by generating of the version number from current time you effectively loosе such an important feature as version. Version does not depends on your decision anymore, it depends on the time of the build, which is pretty much random thing. If you need some time-related attributes, you can have them separately. You can store the time of the build in some data file, documentation, you can even adjust the creation or last modification time of some executable file which could keep your build time documented, but please tell use, for goodness sake, why giving up version management. OK, you could auto-increment last least significant number of the version (revision), but you could establish some sensible versioning policy. The version reflects the decisions you make on the project. For example, you could increment build component of version if you do cosmetic changes on the project, you could increment minor component of version if you do the feature change, and, finally, you could increment the major version if you introduce some major change in the project: change its structure, technology. Something like that. But why giving up version management at all? Did you think that reducing the version number to auto-generated time-based value is effectively the same as not using versions at all?

Why using absolute paths in all cases? Especially the absolute paths generated during development. What, does it mean that you stock file in ever-added directories? It looks really scary. It makes me taking a horrible guess: it looks like you are not using Revision Control System. It it really so? Seriously? If you don't do it, I would not understand: why doing development at all? Just to loose it all on one nice day?

I don't know what else to advice, but I would advise to think about all that. May be even before you figure out where your lost copy operation goes.

—SA
 
Share this answer
 
For those facing similar issues, if you are after a real solution, read on...

MSBuild expects the property defined by itemgroup to be present inside of the target. Replacing ItemGroup tag with Createitem tag helped me to arrive at a solution. Put this in a separate target and call the target from the main target.

<target name="CopyFiles"> 
        <createitem include="$(BuildFolder)_PublishedWebsites\**\*.*">
            <output taskparameter="Include" itemname="YourFilesToCopy" />
        </createitem>
     
        <!--copy build files -->
        <copy sourcefiles="@(YourFilesToCopy)">
        DestinationFiles="@(YourFilesToCopy->'$(IISFolder)\%(RecursiveDir)%(Filename)%(Extension)')"  />
</copy></target>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900