简体   繁体   中英

VS 2015 "Build Dependencies -> Build Customization" always triggers PreBuild and PostBuild

I have a VS 2015 C++ project with both PreBuild and PostBuild steps.

In addition I have a Custom Target added to the project by "Build Dependencies -> Build Customization". The Custom Target runs a Perl script which runs nmake building files with Intel Compiler. The custom target always runs . Specifically the Perl script always runs while nmake checks for changes and prevents building if input files have not changed. Invoking the custom target causes the PreBuild and PostBuild to run even if the custom target did not produce and new output (it ran but did nothing but checks).

I want to prevent PreBuild and PostBuild to run if my Custom Target didn't produce any new output. So far I didn't find a way to do this.

Another option is to prevent the custom target from running if sources have not changed. Unfortunately the files built by the Intel compiler are marked as "Exclude From Build" and thus do not trigger the custom target. I tried to define Input & Output for the task run by the custom target with no luck.

Any help will be highly appreciated!

Make sure your custom targets have an Inputs and Outputs attribute which properly describes which files will be used as input and which one were the resulting output. MsBuild will use the timestamp on these files to decide whether you actually changed anything. The timestamp on these files must be older than the file that would be generated as output from the target, that's how MsBuild decides.

Example:

<Target Name="Custom"   
    Inputs="@(CSFile)"   
    Outputs="hello.exe">  

    <Csc  
        Sources="@(CSFile)"   
        OutputAssembly="hello.exe"/>  
</Target>  

See also:

You can use transforms to map input to output if there is a logical relationship between the two:

<Target Name="Convert"  
    Inputs="@(TXTFile)"  
    Outputs="@(TXTFile->'%(Filename).content')">  

    <GenerateContentFiles  
        Sources = "@(TXTFile)">  
        <Output TaskParameter = "OutputContentFiles"  
            ItemName = "ContentFiles"/>  
    </GenerateContentFiles>  
</Target>  

Do not rely on BeforeTargets and AfterTargets and never rely on PreBuildEvent , as that target itself doesn't have any inputs or outputs and thus always triggers, they're quite old constructs, stemming from the 2003 era, instead override BuildDependsOn and inject your target in the chain.

Example:

<PropertyGroup>
    <BuildDependsOn>
        Convert;
        $(BuildDependsOn);
    </BuildDependsOn>
</PropertyGroup>  

See:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM