Recently I joined a lab project and assigned with a boring task “find all hard-coded strings scattered in the source files which need to be localized, extract them into resource file”…
Obviously, this is a must-do task but few people willing to do it, I don’t want to ruin my reputation and accept this task happily, nobody will keep happy when he or she got to know there’re hundreds of files to be processed, me either… But I decide to finish it smartly, then I think about the write a visual studio add-in to help me “FIND” string candidate and “REPLACE” with correct code automatically, finally I spent 1.5 days to get the add-in work and use another .5 day to finished this task, it’s not bad, if I manually do it, one week might be wasted and a lot of mistakes may appear also…
Creating a VS Addin project is easy from visual studio template, here is an abstract for this add-in, I name it as Thresher:
Replace With Key (CTRL+3)
Some problems I faced during the process, may it help you:
<Compile Include="Properties\Resources.Designer.cs"> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> <DependentUpon>Resources.resx</DependentUpon> </Compile> I’m trying to update .csproj file when Thresher add new Resources files to the project, but later, I found there’s more efficient way to resolve this problem… I guess VS will do something when I manually click “…create one” on the Resources tab of project Properties page, I started procmon.exe (from sysinternals.com) and found VS will find a template located under %VSInstallation%\Common7\IDE\ItemsTemplate\ResourceInternal.zip, I think I found the right solution, I copied Resource.vstemplate and Resource.resX to my Thresher folder and let Thresher call Properties.ProjectItems.AddTemplate(“Resource.vstemplate”, Resources.resx), in this way, it will act the same behavior as we add resources file manually from properties page which means it will add above XML section correctly into .csproj…
I think it’s a nice way to handle the boring job, if you’re working on the similar task now, please check it out, it might help you…download it from the attachment!
register your addin folders to
so all user can load it.
thanks for the tip, Mao.