TFS Checkout Command Line Error 9009 - visual-studio

I'm trying to do a checkout of a file using a prebuild step in visual studio 2012.
When I run the command verbatim on the command line it runs and checks out the file. When I try to use the same command as a prebuild step it exits with code 9009.
Do you really think it can't find the file in the context of the prebuild step? I even used macros vs. direct paths, put things in quotes, checked slash directions (/ vs ) but no luck.
My prebuild step is:
$(DevEnvDir)tf.exe checkout "$(SolutionDir)Includes\js\myFile.js"
I changed tf.exe to DevEnvDir thinking perhaps it couldn't "see" tf.exe, but this still exits with code 9009.
Thanks!

I figured out what it was:
I needed to have quotes on EVERYTHING including tf.exe (that's so annoying)
this doesn't work
$(DevEnvDir)tf.exe checkout "$(SolutionDir)Includes\js\myFile.js"
this does:
"$(DevEnvDir)tf.exe" checkout "$(SolutionDir)Includes\js\myFile.js"

Related

Visual Studio Post Build Event if exists

I want to call a batch file in my post build step in Visual Studio. Locally the batch file exists, just the command
call "$(SolutionDir)PostBuildSen.bat" "$(TargetDir)" "$(TargetName)"
correctly calls and executes the batch file.
However when I want to check if the batch file exists first (since others will use the same Post Build Event), I get the error
:VCEnd" exited with code 255.
The command is
if exists "$(SolutionDir)PostBuildSen.bat" call "$(SolutionDir)PostBuildSen.bat" "$(TargetDir)" "$(TargetName)"
The Diagnostic output tells me
2> Done executing task "Exec" -- FAILED.
How do you handle this?
The Solution Directory contains a folder with an underscore, i.e. \Dev_Main\ and I have read that for the batch file that is to be called at least that doesn't work. However I am not sure if that is the issue with folders as well and how to cope with it. Also, since the call command works, I am not sure this is the problem.
Furthermore, if I replace the call with cmd /C, the exit code is 1 and the (minmal) output tells me
1>The filename, directory name, or volume label syntax is incorrect.
Also, I will add this as a custom command to a CMakeLists file later on, so the solution needs to work with that.
Thanks to Hans Passant's comment, I solved the problem. The query for the file needs to be if exist rather than if exists.

How to make MSBuild print output from a custom tool?

I have a project, which use a .rules file to build some non-c++ sources. How to make MSBuild print diagnostic output from this tool? -- Precisely cerr stream.
(I silently presume, the M$ team have not reached that level of insanity, to give the custom building tools functionality without possibility to print errors from them.)
I've actually noticed you marked question with label visual-studio-2008. I guess it means your custom build tool processes non cpp files in vc2008 project? If so, I think it is not built by msbuild but with vcbuild.
In this case try to add echo on in front of command executed by custom tool.
Vcbuild creates batch files in %temp% that first line contains #echo off and then it is executed. So if you add echo on you should see complete output in output window including command line used for command execution.

VS2010: How to use Environment Variables in Post-Build

On my PC I have created a system environment variable called 3DSMaxInstallDirectory
At the command line, if I give
echo %3DSMaxInstallDirectory%Plugins\
I get
D:\Program Files\Autodesk\3ds Max 2011\Plugins\
In Visual Studio I enter into the Post-Build section
copy "$(TargetDir)$(TargetName).*" "$(3DSMaxInstallDirectory)Plugins\"
However on build I get
Error 4 The command "copy "C:\Users\Sebastian\Documents\Visual Studio 2010\Projects\MaxBridge\MaxBridgeImporterPlugin\bin\Debug\MaxBridgePlugin.*" "Plugins\"
" exited with code 1. MaxBridgeImporterPlugin
The results on Google are a confusing mix of suggestions that Visual Studio doesn't support EVs, Visual Studio does support EVs, Visual Studio needs %..% and Visual Studio needs $(..) - and none of which seem to work on my computer.
What is the correct way to use my environment variable in Visual Studio?
(Yes, the directory exists, and the reason I don't want to set the path explicitly is I am preparing to share this project, and every step someone else has to take after downloading and before building is another barrier.)
This works for me in the Post-Build setting of the 'Build Events' of the project.
echo %CodeContractsInstallDir%
echo %DXSDK_DIR%
echo "%ONLYME%"
ONLYME is a environment var in the User variables of my profile.
The others are System wide vars.
ONLYME stays empty if I start VS2010 as administrator, the systemvars still have values as expected.
I'm on V2010 SP1
The '%' character is reserved by MSBuild, so you have to replace it by the %25 hexadecimal escape sequence as documented in MSDN.
copy "$(TargetDir)$(TargetName).*" "%253DSMaxInstallDirectory%25\Plugins" should actually work. However: Visual Studio's commandline editor displays it correctly, but MSBuild then interprets %253 wrongly. I can't tell whether it's a bug or a feature but you must not start your environment variable's name with a digit.
Visual studio doesn't properly encode/decode "special" characters in the XML config file. I'm able to get it to work as expected by manually escaping the command as a URL (http://www.w3schools.com/tags/ref_urlencode.asp).
ECHO %CD%
Results in an output log:
Target "PreBuildEvent" in file "blahblahblah"
Task "Exec"
Command:
ECHO %CD%
C:\blah\blah\blah\Debug
Done executing task "Exec".
However, using URL escapes in the project proerties dialog appears to work:
ECHO %25CD%25
According to this MS Link, the syntax is now the same as using a project file variable, which means you don't have to worry about escaping the % character anymore. For example, if BIN_PATH is an environment variable and the following line is added to the post build step:
echo $(BIN_PATH)
This line will then display the value of BIN_PATH to the output window after the build.
But, be aware that the environment variable must be defined before VS is started. I lost about 45 minutes when I first tried this before it dawned on me that maybe the reason why it was not working was because VS loads the environment variables on startup. So, I exited VS, restarted, and it worked like a charm.
You still might need the old % character syntax if your environment variable is the same as a VS project variable, since "the property in the project file overrides the value of the environment variable."
If you want to use an environment variable that is defined after VS is started, the rules differ for .vcxproj and .csproj projects. In .vcxproj projects, writing %MY_ENV_VAR% in the Project Properties won't work - you need to use the escape syntax %25MY_ENV_VAR%25. But a .csproj project does accept %MY_ENV_VAR%; using the escape syntax causes the escape sequence to be mangled, giving %2525MY_ENV_VAR%2525. (This in VS2017 at least.)

Can't execute a batch file on post-build

I've read this discussion but despite different attempts, I get an error (it varies depending on my approach).
The compilation itself works fine. Double-clicking on the "publish.bat" files executes it just fine too. It's the combo in VS10 that breaks.
This is what I've tested.
$(OutDir)\publish.bat
"$(OutDir)\publish.bat"
$(OutDir)publish.bat
"$(OutDir)publish.bat"
call $(OutDir)\publish.bat
call "$(OutDir)\publish.bat"
call $(OutDir)publish.bat
call "$(OutDir)publish.bat"
What am I missing?
I had a similar problem that I was just able to fix. For me the simple call "$(SolutionDir)\Setup\CreateInstaller.bat" worked, but I kept getting a The command "call {solution directory}\Setup\CreateInstaller.bat" exited with code {code}. Turns out my batch file was expecting to be run from the directory in which it lived. So, check that all the commands in the batch file are not using relative directories or commands as these may break.
Also, are you sure the $(OutDir) macro is what you want? In VS2010 at least, that is just equal to bin\Debug or bin\Release depending on which version you're building in. It seems unlikely that you really want that directory. I expect what you want is $(SolutionDir) or perhaps even $(TargetDir).

vs.net multi pre-build commands

Hi all I have an external project and I want to build it in the main project for that
I'm using pre-build commands.I want to use multi commands for copying aspx pages and
ascx usercontrols to sercontrol folder.
When I use one command it works but when I write both lines it returns error code 1
and not builds.I tried to put comma between two commands but not worked.
copy $(SolutionDir)\WebUI.PlugIn.UrlUsage\*.aspx $(ProjectDir)\Pages\Report
copy $(SolutionDir)\WebUI.PlugIn.UrlUsage\*.ascx $(ProjectDir)\UserControls\Report
Can you say how to run mlti commands in pre-build events of vs.net?
A good technique is look at the error produced by Visual Studio when the prebuild fails. Copy that error to the command line and run it. That should allow you to see what the issue is more clearly.
In this case it might be something simple like not having quotes round stuff.
It shouldn't make a difference but you don't need the first \ after the $(SolutionDir).

Resources