How do I fix my C# Express pre/post build events? - c#

I have 2 machines that have the Express version of C# on them.
On one, I can build my solution and my build events execute perfectly. On the other, no matter what is put in the event it always fails. The build output has "C:\Documents in not a valid path" or something to that effect, and points to the line in Microsoft.Common.targets that contains Exec WorkingDirectory="$(OutDir)" whether it is a pre or post build event. I have deleted the targets file along with some of the MSBuild files and then repaired .Net hoping that would fix the problem, but no luck.
Any suggestions on what to do next?
Edit: This is the error that I am getting.
"E:\Programs\Visual Studio 2008\Projects\Work\Brandcode Manager....\Tools\Versioner.exe" "E:\Programs\Visual Studio 2008\Projects\C_Sharp\kjCommonFunctions\kjCommonFunctions\Properties\AssemblyInfo.cs"
'C:\Documents' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the path specified.
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(895,9): error MSB3073: The command ""E:\Programs\Visual Studio 2008\Projects\Work\Brandcode Manager....\Tools\Versioner.exe" "E:\Programs\Visual Studio 2008\Projects\C_Sharp\kjCommonFunctions\kjCommonFunctions\Properties\AssemblyInfo.cs"" exited with code 1.

At a guess I would say it is missing quotes somewhere - ie folders with spaces in the name, assuming the actual path is in C:\Documents and Settings\... but would need to see the real build output and the path of your solution file to give a definative answer

Here's what I ended up figuring out.
The username for the autologon account for the computer I was using (generic logon for our shared laptops) included an ampersand (&). I think that may have been causing the problems. When I created another account on that laptop and then compiled from there both my pre & post-build events worked.
KJ

Related

External executable not starting with error "The target process exited without raising a CoreCLR started event"

I created a class library project and configured the properties section debug to start an exe (the.exe) located in the output directory of the build (as shown in the image).
It worked as long as we had a pre-build event copying the exe and all related files from one directory in the output directory of the build. Unfortunatly this is inconvinient and we do not have track which version of the exe is used.
So I created a versioned nuget package to place all the files in the output directory. I confirmed all the required files (I know of) are in the output directory. And since I created the nuget package manually with the CLI I can confirm they are exactly the same files.
But when I try to start the application from Visual Studio 2019 now I get the following error in the debug output:
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program '[16616] the.exe' has exited with code -2147450749 (0x80008083).
Actually both (the.exe and the class library) are .NET 5.
Comparing the changes of the two setups via Git changes does not hold any clues beside adding the nuget and removing the pre-build events.
So any clue what could be the difference/problem and how to get the executable running? May I missed something?
Well, better check twice when you are stating "I confirmed all the required files (I know of) are in the output directory."
The problem was that not all files made it into the output directory.
In my case only the the.exe and the.dll were placed into the output directory. Once I checked again and ensured that also the.runtimeconfig.json (which was missing) were added it was running again and the exception were gone. Though I am not sure if there is a better way than distributing the.runtimeconfig.json.
update visual studio using Visual Studio installer worked for me. This link! helped for me.

Post-build event fails in CruiseControl.Net

Using CC.net with Visual Studio 2012. CC.Netbuilds a C# project with a post-build event:
copy "$(SolutionDir)Instruments\$(OutDir)*.*" "$(TargetDir)" /d
It succeeds in Visual Studio. It fails in CC.Net. This is this error code:
The command "copy "..\..\Instruments\bin\Release\*.*" "W:\Checkout\TeraSoft 1.0\Terasoft\Terasoft\bin\Release\" /d" exited with code 1. [W:\Checkout\TeraSoft 1.0\Terasoft\Terasoft\Terasoft.csproj]
The documentation says error code 1 means "No files were found to copy." But there are numerous files in ..\..\Instruments\bin\Release. I read that error code 1 could also mean that it couldn't find the directory, but if Visual Studio can, then why not CC.Net?
CC.Net successfully builds the project if there is no post-build event. Any ideas about what might be causing it?
Remember that the Cruise Control service runs as a different user. It may be "Local System" or Network Service.
I'm guessing that W: is not mapped for that user. If that's not it then the user probably doesn't have permission to that folder.
I also saw that the command "copy "..\..\Instruments\bin\Release*.*"
is missing a backslash before the "*.*"

VS2013 - How to pass the solution folder, $(SolutionDir), in the command line arguments for a C# project using an external program

I am building a C# adding for Excel. In order to debug it, I need to launch Excel.exe with a command line argument containing the Debug or Release path to the addin.
For example:
Start External Program: C:\Program Files\Microsoft Office\Office15\EXCEL.EXE
Command line argument "C:\Dev\Project1\Project1\bin\Debug\Project1-AddIn64.xll"
However, I would like to replace "C:\Dev\Project1\Project1\bin\Debug" with an equivalent of $(SolutionDir) for C++ projects in VS. Is there a way to do this ? If it is not doable, is there a way to get around this ?
EDIT: please support me and get this added in VS by voting up the following idea: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6350738-support-for-macros-in-debugging-command-line-argum
Indeed, the macros cannot be used in the Start Options | Command line arguments
I see two solutions:
As the current folder is set to the $(TargetDir) when you Start an application you could refer to the solution folder like this: ..\..\..\ if the External program accepts a relative path. (I am not quite sure why you would ever want to refer to the solution folder, referring to the output/target folder makes more sense to me)
In the Post Build event (unregister) and register the component the way the component should be registered when deploying it (a proper setup). This way you only have to refer to Excel in the Start Action. This also immediately adds the benefit of testing a scenario that is more similar to production.
It's not exactly a fix, but this may help some people. If you create your project from the project template "Visual C#/.NET Core/Console App" instead of "Visual C#/Windows/Console App", this feature is supported. When I put "$(SolutionDir)" in the Application Arguments field on the Debug tab of the Project Properties window, it is expanded at run time. Note that you will need Visual Studio 2015 Update 3 or later.
I guess you could make use of post-build event to read in your file. #HansPassant explained it in VS2010 - Project Macro Variables in Start Options Command Line Arguments.
A short quote:
A possible workaround is a post-build event that writes a file that you read in your program. Like echo $(ProjectName) > "$(TargetDir)cmdargs.txt
You could substitute cmdargs.txt to appropriate file you want.
You CAN use the macros in the Command fields. I used procmon.exe to see what VS was looking for and indeed i could use $(SolutionDir)\..\Debug\thetoolname.exe as my solution was not in the root.
Im using VS2019 so AFAIK it is supported from this version but it most likely is supported in lower versions. Just use procmon to check the path that VS is attempting to resolve.

.less prebuild event command throws errors [duplicate]

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.
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.
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.
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.
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
Had the same variable after changing PATH variable from Environmental Variables in Win 7. Changing back to default helped.
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.
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"
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"
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.
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.
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.
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.
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.
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.
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.
I added "> myFile.txt" to the end of the line in the pre-build step and then inspected the file for the actual error.
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.
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.
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.
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=""$(MSBuildThisFileDirectory)\wix\wixscript.bat" $(VersionNumber) $(VersionNumberShort)"
ContinueOnError="false"
IgnoreExitCode="false"
WorkingDirectory="$(MSBuildProjectDirectory)\wix" />
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:
Ctrl+Alt+O
View > Output
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.
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.
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.
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'.
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
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.)
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.
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)
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.

How can I resolve the error: "The command [...] exited with code 1"?

I've read around many questions but I've not been able to find the right answer for me.
As I try to compile a project in VS2012 I have this result:
The command "....\tools\bin\nuget pack Packages\Lib.Html.nuspec - OutputDirectory ....\bin\Zip\Packages -NoPackageAnalysis" exited with code 1.
I looked for the line of code in my .csproj file, where the error should be, and there is:
<Exec Command="$(ProjectDir)..\..\tools\bin\nuget pack $(ProjectDir)Packages\Lib.Html.nuspec -OutputDirectory $(OutputPath)Packages -NoPackageAnalysis" />
What am I doing wrong?
[EDIT]
Launching the Debug of that project and ignoring "building errors", I have a new alert:
"Visual Studio cannot start debugging because the debug target '[project.exe path]' is missing.
Please build the project and retry, or set OutputPath and AssemblyName properties appropriately to point at the correct location for the target assembly."
The first step is figuring out what the error actually is. In order to do this expand your MsBuild output to be diagnostic. This will reveal the actual command executed and hopefully the full error message as well
Tools -> Options
Projects and Solutions -> Build and Run
Change "MsBuild project build output verbosity" to "Diagnostic".
Right click project -> Properties -> Build Events
Remove the text in Post-build event command line text block
For me : I have a white space in my path's folder name G:\Other Imp Projects\Mi.....
Solution 1 :
Remove white space from folder
Example: Other Imp Projects ->> Other_Imp_Projects
Solution 2:
add Quote ("") for your path.
Example: mkdir "$(ProjectDir)$(OutDir)Configurations" //see double quotes
Try to open Visual Studio as admin.
For me, in VS 2013, I had to get rid of missing references under References in the UI project (MVC). Turns out, the ones missing were not referenced.
I know this is too late for sure, but, this could help someone as well.
In my case, i found that the source file is being used by another process which was restricting from copying to the destination. I found that by using command prompt ( just copy paste the post build command to the command prompt and executed gave me the error info).
Make sure that you can copy from the command prompt,
This builds on the answer from JaredPar... and is for VS2017. The same "Build and Run" options are present in Visual Studio 2017.
I was getting, The command "chmod +x """ exited with code 1
In the build output window, I searched for "Error" and found a few errors in the same general area. I was able to click on a link in the build output, and found that the error involved this entry in the .targets file:
<Target Name="ChmodChromeDriver" BeforeTargets="BeforeBuild" Condition="'$(WebDriverPlatform)' != 'win32'">
<Exec Command="chmod +x "$(ChromeDriverSrcPath)"" />
</Target>
In the build output, I also found a more detailed error message that essentially stated that it couldn't find Selenium.WebDriver.ChromeDriver v2.36 in the packages folder it was looking in. I checked the project's NuGet packages, and version 2.36 was indeed in the list of installed packages. I did find the package files for 2.36, and changed the attributes on the folder, subfolders and files from "Read Only" to "Read/Write". Built, but same failure. Sometimes "updating" to a different version of the package and then updating back to the original can fix this type of error. So I "updated" the reference in Manage NuGet packages to 2.37, built, failed, then "updated" back to 2.36, built, and the build succeeded without the "chmod +x" error message.
The project I was building was based on a Visual Studio Project template for Appium test tooling, template name "Develop_Automated_Test".
Check your paths:
If you are using a separate build server for TFS (most likely), make sure that all your paths in the .csproj file match the TFS server paths. I got the above error when checking in the *.csproj file when it had references to my development machine paths and not the TFS server paths.
Remove multi-line commands: Also, try and remove multi-line commands into single-line commands in xml as a precaution. I had the following xml in the *.proj that caused issues in TFS:
<Exec Condition="bl.."
Command=" Blah...
..." </Exec>
Changing the above xml to this worked:
<Exec Condition="bl.." Command=" Blah..." </Exec>
I had the same issue. Tried all the above answers. It was actually complained about a .dll file. I clean the project in Visual Studio but the .dll file still remains, so I deleted in manually from the bin folder and it worked.
Hope this helps someone, but I had prebuild events and post build events and it kept complaining about a file called "Microsoft.Common.CurrentVersion.targets" "The target "CoreBuild" does not exist in the project".
Here's what I did to resolve it:
close the project
delete the .suo file (it regenerates)
Asked a team member to provide a copy of that file (Microsoft.Common.CurrentVersion.targets) - mine was different - I took his.
It compiled - good to go.
I must have wrecked that file somehow.
There was no syntax error in my batch file and it ran fine on a cmd prompt outside VS.
So finally, I added
exit 0
to return a success code explicitly at the end of my batch file and it started working.
For me the output file (.dll) of the same version already existed so I guess it was having trouble overwriting. Even though it has never done it before. Anyways, deleting the existing file and running Rebuild fixed it for me.
If the previous method wouldn't have fixed it, my next check would have been to check if the path length was causing it. So would have change the target folder to somewhere close like the Desktop so that the path isnt too long.
Hint: Search for "Exec Command=" in your project
In my case I found following tag in "Microsoft.Extensions.ApiDescription.Server.targets" file, I remarked the line and it worked for me:
<Exec Command="$(_Command)" LogStandardErrorAsError="true" />

Categories

Resources