none
conditional CopyToOutputDirectory based on definedconstants

    Question

  • HI,

    I have few batch files included in my c# project. which are set as Copy to outputdirectory as always. I want that copytooutput directory should be conditional.Is should be copied to output directory only if DefineConstants is Debug.

    from http://social.msdn.microsoft.com/Forums/eu/msbuild/thread/ed141cf9-4f6a-4ed4-b3e8-e23794fe017f, i am able to do it for c# files by puttin conditinoal remove. as it has no copytooutput directory, but even if i put conditional remove to batch file, it is still copied to output directory.

    Requiremnt: if "debug" build, copy batch file to output. If "Release" do not copy batch file to output directory

    Regards


    singhhome

    • Edited by singhhome Saturday, October 22, 2011 4:08 PM
    Saturday, October 22, 2011 3:59 PM

Answers

  • Hi Singhhome,

     

    Whether the file will be copied to output is defined in a  ItemGroup.  We can setup a condition for the such ItemGroup to control if the list of files should to be copied. You can unload the project and open the project file in the editor, and try to find the ItemGroup which represents the list of the files. The following sample demos a txt file to be copied depends on the definedconstants.

     

       <ItemGroup Condition="'$(DefineConstants)' == 'DEBUG;TRACE' ">

        <Content Include="TextFile1.txt">

          <CopyToOutputDirectory>Always</CopyToOutputDirectory>

        </Content>

      </ItemGroup>

     

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by singhhome Tuesday, October 25, 2011 5:37 PM
    Monday, October 24, 2011 6:28 AM