1

How can I always run a custom script in Visual Studio 2015, even if nothing has changed... but using VS without VS++ installed?

I effectively want to do the same as this question however, my installation of Visual Studio 2015 does not have VC++ installed (as everything we do is either C# or VB.Net) so I do not have access to the same project properties pages.

Using the accepted answer as a starting point, and this article for more details I have added the following to my project file, but I simply cannot get it to run the custom script unless a file in the project has changed...

<PropertyGroup>
  <ItemDefinitionGroup>
    <CustomBuildStep>
      <Command>MyScript.vbs</Command>
      <Outputs>$(TargetName).missing</Outputs>
      <Inputs>$(TargetFileName)</Inputs>
    </CustomBuildStep>
  </ItemDefinitionGroup>    
</PropertyGroup>
<PropertyGroup>
  <CustomBuildAfterTargets>ClCompile</CustomBuildAfterTargets>
  <CustomBuildBeforeTargets>Link</CustomBuildBeforeTargets>
</PropertyGroup>  

I have done a lot of searching for values for <CustomBuildAfterTargets> and <CustomBuildBeforeTargets> but I cannot find anything official or otherwise. It's highly frustrating for the MS article not to provide details on possible values.

I did also try adding the <DisableFastUpToDateCheck> attribute as per one of the answers, but that still rebuilds the project so isn't what I want.

freefaller
  • 19,368
  • 7
  • 57
  • 87
  • Do you want to run this on a particular file, file type, or on the project as a whole? – battlmonstr Mar 11 '19 at 15:39
  • @battlmonstr - The project as a whole. Even if nothing has changed in any of the project files, I want a build to run the script – freefaller Mar 11 '19 at 15:40
  • Have you tried defining this in UI? Like going to project settings, build steps and set your command there? – battlmonstr Mar 11 '19 at 15:55
  • @battlmonstr - thanks for your comments. I have repeatedly stated (including in the title) that I do not have VC++ installed, and therefore I don't get the same property pages. So no, I haven't, because I don't have them... hence my question – freefaller Mar 11 '19 at 16:02
  • @freefaller, are you building c# or c++? ClCompile is a c++ compile target, not a c# compile target (see https://stackoverflow.com/questions/49591809/is-the-clcompile-item-a-task-as-well). I think you may be needing CoreCompile for c# (see https://stackoverflow.com/questions/11667510/determine-if-msbuild-corecompile-will-run-and-call-custom-target?noredirect=1&lq=1). – user9525052 Mar 11 '19 at 17:34
  • @user9525052 - thanks for your response - I need C# and preferable VB.Net. I'll investigate the links you've provided – freefaller Mar 11 '19 at 17:40
  • Look at adding an Exec target to your project file. Any halfway interesting customization in builds doesn't tend to fit all that well into the customization points that are supported in the project property pages, so you might end up with something that works better anyway. – Craig Mar 12 '19 at 14:32
  • Are you saying you don't have the "Build Events" tab on your project's property pages? I have it on both C# and VB projects. – Chris Dunaway Mar 12 '19 at 14:42
  • @Chris - no, I'm not saying that. I have "Build Events" (although not a tab, it's a button on the "Compile tab")... but it only provides pre-build and post-build events, both of which only fire when something has changed in the project – freefaller Mar 13 '19 at 13:35

1 Answers1

0

I ran into a similar problem while trying to run a script that generated source code from a folder's contents.

I managed to trigger the Custom Action every time by adding a directory to the list of Inputs:

    <CustomBuildStep>
      <Outputs>all_templates.h</Outputs>
      <Inputs>Generate-TemplateFileHeader.ps1;$(ProjectDir)..\web\webadmin\</Inputs>
    </CustomBuildStep>

I hoped that the build system might detect changes to the directory and subsequently run the custom build step. It does not. Instead, it seems to always run the custom action.

Caveat: I do not know if this is documented behavior. It could be purely accidental or based on my environment.

veefu
  • 2,820
  • 1
  • 19
  • 29