Resource files not being copied to /bin when compiled thru VS

FrancineTaylor used Ask the Experts™
My company has a product with a large number of standalone modules (AP, AR, etc).  It is written in C# and VB.NET, developed with VS, currently compiled in 2010.

One of my areas of responsibility is the icons, mostly contained in .resource files.  There are about a dozen .resource files, most needing to be copied into all the modules' /bin directories.

Here's the behavior that we are experiencing.  Say I modify a .resource file.  I check it into Subversion and it goes into the pipeline to be distributed to QA and UX through the normal build.  No problems there.

But when other developers try to compile, they end up getting the old version of the .resource file copied into their /bin directories.  If a new .resource file was added, they don't get it at all.  If they copy it manually, it is blown away and overwritten each time they compile.  So we have to use batch files to do a manual copy, run after the application is started up but before we enter our login.

What mechanism does the copy of those .resource files during compilation, and how can I access it?  I'm guessing it must be something individual to each project, because there are some modules that copy everything correctly, some which copy incorrectly only if you manually delete the contents of /bin, and some which delete and copy incorrectly every time.

Can someone point me to the script or project area that controls this process?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015
How are you using your resource files?

Usually, specially for images, resource files are not copied to bin, they are embedded in the application. If you select a resource file in the Solution Explorer and check in the property windows, it is marked as an embedded resource by default. If this is so, it should be included in the application each time one of your programmers compile it.

Only with multilanguage or special situations are resource files added to the distribution, but usually not as a resource. By default Visual Studio compile them one or more satellites .dll files.

It seems that you are not using that way of working.

You are also using a versioning control system. I do not know about Subversion, but has it been designed with .NET in mind. Maybe it does not follow the rules.

I bet that you could correct your program someway by playing with the resource files properties in the Properties window.

One thing that could happen for instance (once again, I do not know Subversion). The way it looks, you are moving a copy to the compilation directory, so the CopyToOutputDirectory is probably set to something else than DoNotCopy, which is the default. What could happen, if Subversion works like other versionings system I have used, is that everytime one of your programmers compiles, the local copy of the resources he has gets copied over the one you modified. In such a case, setting the CopyToOutputDirectory to CopyIfNewer might solve the problem.

Just a guess.

Another way to possibly go, if your environment does not prevent it, is to create a script that is activated each time the application compile, after compilation, and make sure that the latest version of the resource files gets copied in the destination directory. There is a Build Events button in the Compile tab of the Project Properties window that would enable you to create such a batch operation.

I hope this leads you toward a solution.


The reason we are doing our icons with .resource files is that we have hundreds of icons and dozens of projects and embedding every icon in every project is just not practical.  This way, an icon change only requires that we edit a single file instead of dozens.

The post build event sounds like the best candidate for what I want.  I've discovered that there's some kind of complicated deployment scripting that does the job for the compiled/installed systems, which is why things work for them.  The resource files aren't even included anywhere in the projects that I can find.  I have no idea what mechanism is copying them in the first place but they expect me to fix the process.

I'd like to build a batch file in the highest directory that takes in the resource files and all the modules.  The name of it is ClientSide.  The batch file would copy all .resources files from the directory where they are stored, into the bin directory of the project being compiled.

So, the batch file would say:

copy /ResourceRepository/*.resources  <bin of current project>

Then I would want to put something in the project's Post Build Event Command Line to say execute this file, which would reside two directories lower, and would need to take the project name or directory path as a parameter.

How would I tell the batch file to take a parameter?  Just "%1"?  And then how would I get the path and send it as a parameter?  Remembering that it is not just the current directory that I need, but the one below it as well?

So, as an example, if my top level directory was /ClientSide, and my project was /ClientSide/AR/AR_Host, I would need to send "/AR/AR_Host" to the batch file.
Top Expert 2015

Search the documentation for "Pre-build Event/Post-build Event Command Line Dialog Box". You will get a list of the macro commands that you can use inside those scripts. The one for the bin is $(TargetDir). There are many others to get the project directory, the solution directory, paths relative to a few others, etc.

I suggest that you also give a look to the references in the See Also of that documention page. You will get a few sample scripts that could be useful.
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.


I've looked through that documentation and all the examples I could find, but I am still unable to find the key element to this task.  How would I call a batch file which is one directory below $(SolutionDir)?

I've tried:    call  ..\$(SolutionDir)frantest.bat

...but got this error:

The command "call ..\c:\ClientSide\VP\frantest.bat" exited with code 1

I can see how it misinterpreted what I asked for, but I don't know how to fix it...
Top Expert 2015

I understand your need better with the last post.

As I see them, the build event scripts use Visual Studio standards. In Visual Studio, the project directory is seen as a root and everything is under that directory. So they do not react to some other standards such as the ..\ to move up one directory.

However, the script can call an executable file and pass command lines parameters to it. You have an example of such an .exe in the "How to: Specify Build Events (Visual Basic)" topic of the documentation.

An application will react to the ..\. Store it on a network drive that is seen by all the programmers and call it from you script, passing $(SolutionDir) as a parameter. The application will do the job.
James, thank you for all your help.  You have given me a lot of useful ideas and pointed me in the right direction (Build Events) to solve the problem.

The network drive solution wasn't an acceptable option, as it doesn't really lend itself to version control.  What I eventually ended up with is this.

During the post build event, all commands are executed relative to the /bin directory, the same directory as $(TargetDir).  So I just put the batch file in the same directory with the resources files, and call it relative to the /bin.

     call  ..\..\..\RepositoryFiles\PostBuildResourceCopy.bat $(TargetDir)

The batch file has this command:

     copy ..\..\..\RepositoryFiles\*.resources %1

(Note, since it is run from the /bin directory, it has to reference the files from there).  It seems to be working great.


Thanks again for spending so much time helping me!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial