简体   繁体   中英

Visual Studio MSbuild rename file event

I am writing a extension for visual studio, which will automatically generate some JS file according to ascx code.

 public class JSCodeGenTask : Task

This Task is registered as a after-build task, which means it will be executed after every build. The class extends Task, and is registered in csproj.

   <Target Name="AfterBuild">
      <JSCodeGenTask FileNames="@(something)" outPath="@(somethingelse)" />
   </Target>

The problem is, I want to keep track of programmers renaming an ascx file, namely, I want the former name of that ascx file. Is there a way to access this information?

 public event RenamedEventHandler Renamed

I know renamed event can be used here, but I don't know how to register this event to Visual Studio -- .csproj. Thanks!

I guess I've found the solution

http://msdn.microsoft.com/en-us/library/bb166508%28VS.100%29.aspx

It should be implemented as a Custom Tool instead of MSbuild event. Examples can be found at

http://code.msdn.microsoft.com/SingleFileGenerator#BuildAndRun

I think it will be easer to write target. All you need is create appropriate ItemGroup with *.ascx files. You can grab them all (or with filter applied) from Content

<Target Name="AfterBuild" DependsOnTargets="GenerateScripts" />
<Target Name="GenerateScripts">
  <ItemGroup>    
       <AscxFiles Include="@(Content)" Condition="'%(Extension)'=='.ascx'" />
  </ItemGroup>
  <JSCodeGenTask FileNames="@(AscxFiles)" OutPath="$(OutPath)" />
</Target>

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