简体   繁体   中英

C# pre-build event doesn't appear to be expanding macro symbols?

I have a C# Project with the following line in the Pre-Build events:

copy "(RSSDK_DIR)\\bin\\win32\\libpxccpp2c.dll" "($OutDir)" /Y

RSSDK_DIR is an environment variable and $OutDir is a recognized macro symbol. I am trying to copy the given DLL from the first directory to the output directory.

When I build the project I get the error:

Error   1   The command "copy "(RSSDK_DIR)\bin\win32\libpxccpp2c.dll" "($OutDir)" /Y" exited with code 1.   

I have done a similar task in C++ projects and it worked fine. In addition, you could see the actual command fully expanded being run when the build event fires in the Output window. In this case with my C# project, it doesn't appear to be expanding either the environment variable or the macro symbol. I've read other SO posts on doing a file copy like this and my version appears to be the same as what I've seen.

How can I get this to work and are there any IDE settings or tools to help debug this?

Try this, for specific macro variables the correct syntax is $(OutDir) instead of ($OutDir)

For environment variables you have to use the %variable% syntax, but because % is a reserved character in MSBuild you will need to replace it with %25.

That does not work for me either, but good news is you could use the same syntax for environment variables though.

So you command should work like this

copy "$(RSSDK_DIR)\bin\win32\libpxccpp2c.dll" "$(OutDir)" /Y

Notice that inside visual studio $(OutDir) is a virtual path and depending on what you are trying to do, you should consider using $(TargetDir) instead.

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