CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeffrey Palermo [MVP]

Software management consultant and CTO, Headspring Systems

Making images in .resx files available to other projects (they default to internal) - level 200

I find it very frustrating that there is no obvious way to have the .resx generator mark members as public instead of internal.  In my team's solution, we have a need for these to be public.  Here's how I solved it:

Add a nant target that can do a find/replace in a file (I don't know of a shell command that will do that)

<?xml version="1.0" encoding="utf-8"?>

<!--EXTERNAL_PROPERTIES: filename;stringToReplace;newString-->

<project name="BuildTasks" xmlns="http://nant.sf.net/release/0.85-rc4/nant.xsd">

  <target name="FindReplace">

    <move file="${filename}" tofile="${filename}.bak">

      <filterchain>

        <replacestring from="${stringToReplace}" to="${newString}" />

      </filterchain>

    </move>

 

    <move file="${filename}.bak" tofile="${filename}"/>

  </target>

</project>



Add a pre-build step to the project to run this target and feed in the correct file:
pushd .
cd "$(ProjectDir)..\..\"
bin\nant\nant.exe -buildfile:buildtasks.build FindReplace -D:filename="$(ProjectDir)\Properties\Icons.Designer.cs" -D:stringToReplace=internal -D:newString=public
bin\nant\nant.exe -buildfile:buildtasks.build FindReplace -D:filename="$(ProjectDir)\Properties\ToolbarIcons.Designer.cs" -D:stringToReplace=internal -D:newString=public
popd
Compile as you normally would and note the output:
------ Build started: Project: MyProject, Configuration: Debug Any CPU ------
pushd .
cd "C:\svn\MyProject-trunk\src\MyProject\..\..\"
bin\nant\nant.exe -buildfile:buildtasks.build FindReplace -D:filename="C:\svn\MyProject-trunk\src\MyProject\\Properties\Icons.Designer.cs" -D:stringToReplace=internal -D:newString=public
bin\nant\nant.exe -buildfile:buildtasks.build FindReplace -D:filename="C:\svn\MyProject-trunk\src\MyProject\\Properties\ToolbarIcons.Designer.cs" -D:stringToReplace=internal -D:newString=public
popd
NAnt 0.85 (Build 0.85.2344.0; rc4; 6/2/2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/svn/MyProject-trunk/buildtasks.build
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: FindReplace


FindReplace:

[move] 1 files moved.
[move] 1 files moved.

BUILD SUCCEEDED

Total time: 0 seconds.

NAnt 0.85 (Build 0.85.2344.0; rc4; 6/2/2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/svn/MyProject-trunk/buildtasks.build
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: FindReplace


FindReplace:

[move] 1 files moved.
[move] 1 files moved.

BUILD SUCCEEDED

Total time: 0 seconds.

Compile complete -- 0 errors, 0 warnings
MyProject -> C:\svn\MyProject-trunk\src\MyProject\bin\Debug\MyProject.dll
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========


Comments

Ayende Rahien said:

would it be simpler to do:

resgen /public file.resx?

# November 10, 2006 5:46 PM

Jeffrey Palermo said:

I'll have to try that out.  Thanks, Ayende.

# November 12, 2006 1:41 PM

About Jeffrey Palermo

Jeffrey Palermo is a software management consultant and the CTO of Headspring Systems in Austin, TX. Jeffrey specializes in Agile coaching and helps companies double the productivity of software teams. Jeffrey is an MCSD.Net , Microsoft MVP, Certified Scrummaster, Austin .Net User Group leader, AgileAustin board member, INETA speaker, INETA Membership Mentor, Christian, husband, father, motorcyclist, Eagle Scout, U.S. Army Veteran, and Texas A&M University graduate. Check out Devlicio.us!

This Blog

Syndication