336

What does this error message mean? What could I do to correct this issue?

AssemblyInfo.cs exited with code 9009


The problem is probably happening as part of a post-build step in a .NET solution in Visual Studio.

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188

36 Answers36

254

Did you try to give the full path of the command that is running in the pre- or post-build event command?

I was getting the 9009 error due to a xcopy post-build event command in Visual Studio 2008.

The command "xcopy.exe /Y C:\projectpath\project.config C:\compilepath\" exited with code 9009.

But in my case it was also intermittent. That is, the error message persists until a restart of the computer, and disappears after a restart of the computer. It is back after some remotely related issue I am yet to discover.

However, in my case providing the command with its full path solved the issue:

c:\windows\system32\xcopy.exe /Y C:\projectpath\project.config C:\compilepath\ 

Instead of just:

xcopy.exe /Y C:\projectpath\project.config C:\compilepath\

If I do not have the full path, it runs for a while after a restart, and then stops.

Also as mentioned on the comments to this post, if there are spaces in full path, then one needs quotation marks around the command. E.g.

"C:\The folder with spaces\ABCDEF\xcopy.exe" /Y C:\projectpath\project.config C:\compilepath\

Note that this example with regards to spaces is not tested.

Jeroen
  • 60,696
  • 40
  • 206
  • 339
thehhv
  • 3,338
  • 1
  • 23
  • 19
  • 47
    I also received the 9009 error on post and pre build events. Checking the Output tab in Visual Studio shows the problem. In my case I was trying to access a path containing a space – Phil Hale May 02 '11 at 15:04
  • 16
    I had a similar problem to this, but it was the result of spaces in the folder names. Putting the paths in quotes (`"$(SolutionDir)packages\NUnit.2.5.10.11092\tools\"nunit-console "$(TargetPath)"`) resolved it. – Justin Morgan - On strike Nov 18 '11 at 19:50
  • 1
    I encountered a similar issue with a pre-build event that used a Java applet to pre-compile JS and CSS...turns out we had neglected to put the Java Runtime on the server. – saluce May 11 '12 at 19:29
  • 2
    Is it possible that the `PATH` environment variable gets lost somehow? I get this error every now and then. I have `npm install` setup as a pre-build event, and initially it works (so I presume everything is setup), but then randomly it will stop working during the day (generally when switching between solutions / branches I believe), and it will no longer know about `npm`. Restarting VS 'fixes' it... meaning my `PATH` is setup correctly, but seems to get up by VS. If there was a way to view the env variables from inside VS I could confirm this. – jamiebarrow Oct 07 '14 at 09:32
  • So, I've installed Powershell Tools for Visual Studio. Trying `gci env:Path | format-list` seems to point to VS messing up its internal state of the `PATH` variable? – jamiebarrow Oct 07 '14 at 10:05
  • Yup, If I run `$env:Path+=";C:\Program Files\nodejs"` in the Powershell Tools window, the build proceeds again... where do I submit a bug report :) – jamiebarrow Oct 07 '14 at 12:45
  • 2
    If you want to protect your build from crashing in different environments, let's say, windows installed on D:\, use environment vars in conjunction of @thehhv answer: ``%systemroot%\System32\xcopy ...`` – Dorival Jul 10 '15 at 21:29
  • Adding quotation marks resolved this for me, but I am running the command via a .proj file, so I needed to encode the quotation marks as " – nickspoon Sep 03 '15 at 01:28
  • Must be nice to be these people in the comments. Quoting doesn't work for me. How can anyone stand to use windows build tools? They are infuriating. – doug65536 Sep 04 '16 at 21:20
  • Restarting fixed it – Bishoy Hanna Jul 05 '17 at 02:57
  • If doing this in MSBuild, use ```"``` to surround the command. – Freddie Mar 05 '18 at 21:03
  • As mentioned above, missing command. In our case git.exe on a developer's PC needed by the .csproj file that contained an execution target to fill the assemblyinfo.cs file: the BeforeBuild target ` ` – Ben Butzer Sep 07 '22 at 20:18
141

Error Code 9009 means error file not found. All the underlying reasons posted in the answers here are good inspiration to figure out why, but the error itself simply means a bad path.

Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
  • 1
    My issue with file not found was the reference in the csproj file was $(PROGRAMFILES)\Microsoft SDKs\TypeScript\tsc and had to be $(PROGRAMFILES)\Microsoft SDKs\TypeScript\1.0\tsc – RHAD Jul 10 '14 at 08:41
  • Thanks for actually answering the first question. – AntonK Jan 24 '18 at 00:00
  • And it means not finding any file the attempted command may be involving, thus even when it couldn't find the command itself. I was using delete instead of del. That would give you a 9009 too. – Mircea Ion Jul 05 '19 at 16:40
88

It happens when you are missing some environment settings for using Microsoft Visual Studio x86 tools.
Therefore, try adding as a first command in your post-build steps:

For Visual Studio 2010 use:

call "$(DevEnvDir)..\Tools\vsvars32.bat"

As @FlorianKoch mentioned in comments, for VS 2017 use:

call "$(DevEnvDir)..\Tools\VsDevCmd.bat"

It should be placed before any other command.
It will set environment for using Microsoft Visual Studio x86 tools.

HRKoder
  • 1,646
  • 15
  • 11
  • 3
    Could you help me out - where and into which file do i have to add the line `call "$(DevEnvDir)..\Tools\vsvars32.bat"`? Thanks – surfmuggle Oct 16 '12 at 19:40
  • 2
    I had to add an entry to my `Path` environment variable. Check the Output window for more information. – crthompson Dec 06 '13 at 05:19
  • Caution. This will fail on many build servers: http://blogs.clariusconsulting.net/kzu/devenvdir-considered-harmful/ – George Mauer Sep 24 '14 at 19:36
  • 2
    Thank you, for x64 bit toolchain I solved like so: "$(DevEnvDir)..\VC\vcvarsall.bat" – codekiddy Jan 26 '15 at 21:59
  • It might be worth mentioning that this bat will easily add 3+ seconds to whatever runs it. This is why the VS Command Prompt takes significantly longer to run than a normal command prompt to start (3+ seconds vs 0 seconds). Might not be a big deal, but worth mentioning. If you're using it to prevent needing to enter a few extra chars by providing a full path to an exe... well stop being lazy :). There are other reasons, though, why this would be helpful. – Adam Plocher Jul 16 '17 at 00:48
  • Late comment, but perhaps important to you as it was to me: -- The `call ...vsvars32.bat` call _may_ change your drive and current directory. In a batch script, a mere `cd %~dp0` will change the current directory, BUT NOT THE DRIVE. If you are doing this in a script, then use `pushd %~dp0` to force it to also reset the drive. – Jesse Chisholm Feb 05 '18 at 18:31
  • 1
    For VS 2017 the file is `"$(DevEnvDir)..\Tools\VsDevCmd.bat"` – Florian Koch Aug 22 '19 at 11:06
58

Most probably you have space in your resultant path.

You can work around this by quoting the paths, thus allowing spaces. For example:

xcopy "$(SolutionDir)\Folder Name\File To Copy.ext" "$(TargetDir)" /R /Y /I
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
NileshChauhan
  • 5,469
  • 2
  • 29
  • 43
  • 9
    +1 - This is exactly the problem I was having. A command in my post-build worked when I built the project locally, but failed when it was built on the build server. I just placed the command between double quotes to fix it. Thanks. – sheikhjabootie Sep 29 '11 at 03:14
  • So is it reasonable to speculate that error 9009 is "file not found"..? Personally, I think the question "what is MSBuild error 9009?" should be perfectly fine as a stand-alone question, but directed to Microsoft! – The Dag Jul 01 '13 at 14:48
12

Had the same variable after changing PATH variable from Environmental Variables in Win 7. Changing back to default helped.

10

I have had the error 9009 when my post build event script was trying to run a batch file that did not exist in the path specified.

SleepyBoBos
  • 1,411
  • 2
  • 11
  • 16
8

My exact error was

The command "iscc /DConfigurationName=Debug "C:\Projects\Blahblahblah\setup.iss"" exited with code 9009.

9009 means file not found, but it actually couldn't find the "iscc" part of the command.

I fixed it by adding ";C:\Program Files\Inno Setup 5 (x86)\" to the system environment variable "path"

scw
  • 5,450
  • 8
  • 36
  • 49
6

In my case I had to "CD" (Change Directory) to the proper directory first, before calling the command, since the executable I was calling was in my project directory.

Example:

cd "$(SolutionDir)"
call "$(SolutionDir)build.bat"
Mathias Lykkegaard Lorenzen
  • 15,031
  • 23
  • 100
  • 187
  • 1
    This fixed the problem for me running Visual Studio's devenv.exe, but you don't need to specify the folder the second time, just'call build.bat will do – FrinkTheBrave May 06 '17 at 07:44
6

I caused this error to happen when I redacted my Path environment variable. After editing, I accidentally added Path= to the beginning of the path string. With such a malformed path variable, I was unable to run XCopy at the command line (no command or file not found), and Visual Studio refused to run post-build step, citing error with code 9009.

XCopy commonly resides in C:\Windows\System32. Once the Path environment variable allowed XCopy to get resolved at DOS prompt, Visual Studio built my solution well.

GregC
  • 7,737
  • 2
  • 53
  • 67
5

Check the spelling. I was trying to call an executable but had the name misspelled and it gave me the exited with code 9009 message.

Mark
  • 1,455
  • 3
  • 28
  • 51
5

If the script actually does what it needs to do and it's just Visual Studio bugging you about the error you could just add:

exit 0

to the end of you script.

hakksor
  • 1,380
  • 1
  • 9
  • 14
4

The problem in my case occurred when I tried to use a command on the command-line for the Post-build event in my Test Class Library. When you use quotation marks like so:

"$(SolutionDir)\packages\NUnit.Runners.2.6.2\tools\nunit" "$(TargetPath)" 

or if you're using the console:

"$(SolutionDir)\packages\NUnit.Runners.2.6.2\tools\nunit-console" "$(TargetPath)"

This fixed the issue for me.

perlyking
  • 557
  • 7
  • 14
pdvries
  • 1,372
  • 2
  • 9
  • 18
4

Another variant:

today I call python interpreter from cron in win32 and take ExitCode (%ERRORLEVEL%) 9009, because system account used by cron don't have path to Python directory.

Denis Barmenkov
  • 2,276
  • 1
  • 15
  • 20
4

tfa's answer has been downvoted, but actually can cause this issue. Thanks to hanzolo, I looked in the output window and found the following:

3>'gulp' is not recognized as an internal or external command,
3>operable program or batch file.
3>D:\dev\<filepath>\Web.csproj(4,5): error MSB3073: The command "gulp clean" exited with code 9009.

After running npm install -g gulp, I stopped getting this error. If you're getting this error in Visual Studio, check the output window and see if the issue is an unset environment variable.

R. Salisbury
  • 1,954
  • 16
  • 17
3

I added "> myFile.txt" to the end of the line in the pre-build step and then inspected the file for the actual error.

Philip
  • 198
  • 1
  • 5
3

I fixed this by simply restarting Visual Studio - I had just run dotnet tool install xxx in a console window and VS hadn't yet picked up the new environment variables and/or path settings that were changed, so a quick restart fixed the issue.

keithl8041
  • 2,383
  • 20
  • 27
3

Also, make sure there are no line breaks in the post build event editing window on your project. Sometimes copying the xcopy command from the web when it's multi-line and pasting it into VS will cause a problem.

jesse p
  • 321
  • 2
  • 6
  • Although jesse makes a good point about not having line breaks in the middle of an xcopy command, note that in the general case it is valid to have line breaks in this field; each line should be interpreted as its own command. – RJFalconer Jan 15 '13 at 17:12
2

For me, disk space was low, and files that couldn't be written were expected to be present later. Other answers mentioned missing files (or misnamed/improperly referenced-by-name files)--but the root cause was lack of disk space.

ErikE
  • 48,881
  • 23
  • 151
  • 196
2

For me it happened after upgrade nuget packages from one PostSharp version to next one in a big solution (~80 project). I've got compiler errors for projects that have commands in PreBuild events.

'cmd' is not recognized as an internal or external command, operable program or batch file. C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1249,5): error MSB3073: The command "cmd /c C:\GitRepos\main\ServiceInterfaces\DEV.Config\PreBuild.cmd ServiceInterfaces" exited with code 9009.

PATH variable was corrupted becoming too long with multiple repeated paths related to PostSharp.Patterns.Diagnostics. When I closed Visual Studio and opened it again, the problem was fixed.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
2

Yet another variant of file not found, because of spaces in the path. In my case in the msbuild script. I needed to use HTML style &ampquot; strings within the exec command.

<!-- Needs quotes example with my Buildscript.msbuild file --> 
<Exec Command="&quot;$(MSBuildThisFileDirectory)\wix\wixscript.bat&quot; $(VersionNumber) $(VersionNumberShort)" 
    ContinueOnError="false" 
    IgnoreExitCode="false" 
    WorkingDirectory="$(MSBuildProjectDirectory)\wix" />
Ben Butzer
  • 915
  • 10
  • 24
2

Same as the other answers, in my case it was because of the missing file. To know what is the missing file, you can go to the output window and it will show you straight away what went missing.

To open the output window in Visual Studio:

  1. Ctrl+Alt+O
  2. View > Output

enter image description here

Marvin Glenn Lacuna
  • 1,682
  • 1
  • 19
  • 25
1

This is pretty basic, I had this problem, and embarrassing simple fail.

Application use Command line arguments, I removed them and then added them back. Suddenly the project failed to build.

Visual Studio -> Project Properties -> verify that you use 'Debug' tab (not 'Build Events' tab) -> Command Line Arguments

I used the and Post/Pre-build text area, which was wrong this case.

ken1nil
  • 915
  • 3
  • 9
  • 21
1

My solution was just simple as: have you tried turning it off and on again? So I restarted the computer and the issue was gone.

krzyszt0fd
  • 86
  • 7
1

I also ran into this 9009 problem when facing an overwrite situation.

Basically, if the file already exists and you have not specified the /y switch (which automatically overwrites) this error can happen when run from a build.

Travis Vroman
  • 364
  • 2
  • 9
1

Happened with a colleague. If development environment is windows and visual studio project is on C: drive.. Than make sure that visual studio is run with administrator right.. simply right click and 'Run as administrator'. You can also go to the properties of visual studio project -> Advance -> and enable 'Run as administrator'.

Mohit Pundir
  • 109
  • 1
  • 7
1

I had the same error caused by my post build script and I tried to run the script line by line in the command prompt. Finally I found out the root cause is I did not populate the missing information in the .nuspec file, i.e. replacing all the variables between $ and $ with the actual value, e.g. replacing $author$ with my name

yangli.liy
  • 101
  • 3
  • 5
1

Check the Output tab carefully.

That should reveal the issue reason.

(E.g. in my case it was related to a comment: '#' is not recognized as an internal or external command, operable program or batch file.)

Chris W
  • 1,562
  • 20
  • 27
1

I had similar issue and I received:

The command ""C:\Users<user>\Downloads\sandbox-attacksurface-analysis-tools-c02ed8ba04324e54a0a188ab9877ee6aa372dfac\packages\XmlDoc2CmdletDoc.0.3.0\build..\tools" -excludeParameterSets "" -strict "C:\Users<user>\Downloads\sandbox-attacksurface-analysis-tools-c02ed8ba04324e54a0a188ab9877ee6aa372dfac\bin\Debug\NtObjectManager.dll"" exited with code 9009.

I went to the project properties > Build and unchecked the XML documentation file:
enter image description here

After that, I rebuild the project and it disappeared. The weird thing is that after I checked the checkbox again and rebuild it, the error didn't return.
Ghosting bug..

E235
  • 11,560
  • 24
  • 91
  • 141
0

Actually I noticed that for some reason the %windir% environment variable sometimes get erased. What worked for me was re-set the windir environment variable to c:\windows, restart VS, and that's it. That way you prevent having to modify the solution files.

Charles F
  • 114
  • 1
  • 5
0

At least in Visual Studio Ultimate 2013, Version 12.0.30723.00 Update 3, it's not possible to separate an if/else statement with a line break:

works:

if '$(BuildingInsideVisualStudio)' == 'true' (echo local) else (echo server)

doesn't work:

if '$(BuildingInsideVisualStudio)' == 'true' (echo local) 
else (echo server)
else42.de
  • 465
  • 5
  • 23
0

Yet another reason: If your pre-build event references another projects bin path and you see this error when running msbuild, but not Visual Studio, then you have to manually arrange the projects in the *.sln file (with a text editor) so that the project you are targeting in the event is built before the event's project. In other words, msbuild uses the order that projects are listed in the *.sln file whereas VS uses knowledge of project dependencies. I had this happen when a tool that creates a database to be included in a wixproj was listed after the wixproj.

Novaterata
  • 4,356
  • 3
  • 29
  • 51
0

I think in my case there were russian symbols in path (all projects were in user folder). When I put solution in another folder (directly on disk), everything became ok.

Dmitriy Dokshin
  • 710
  • 5
  • 25
0

My solution was to create a copy of the file and add a step to the build task to copy my file over the original.

johnrizzo1
  • 31
  • 3
0

it happen with me when i change properties of App.config to be Copy Always

and fix it by undo all my edits then build to make sure it worked

finally reset it again copy always and build it worked

0

I actually got this error message when signtool.exe itself could not be found. To fix this I added the folder path to the PATH environment variable and restarted Visual Studio.

Adam Short
  • 75
  • 1
  • 6
-1

You need to make sure you have installed grunt globally

tfa
  • 1,643
  • 16
  • 18