How to resolve console application exited with code 9009 - c#

Im try to run a c# console application in build process by using below command
<Target Name="AfterBuild" AfterTargets="AfterBuild">
<Exec Command="$(ProjectDir)$(OutputPath)$(AssemblyName).$(OutputType)" />
</Target>
Error when Build : error exited with code 9009
Note : This error occurs due to my project have space in parent folders
this same scenario working fine when parent folder name does not have space
How to resolve this issue?

Related

Could not load file or assembly 'Microsoft.Management.Infrastructure

I am writing a multi-platform c# command line application using .NET Core 3.1 that will need to work as a single executable. I am using Visual Studio 2019 (16.5.4). My OS is Windows 10.0.18363.778 and I intentionally did NOT install Powershell 7. I tested this first bit on my Windows and WSL Ubuntu and it worked until I added Powershell SDK 7. After I installed Microsoft.Powershell.SDK 7.0.0 and when Ì set the project file as follows, everything runs nicely and I can validate I am using PS7 and not Windows PS.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
However, when I add the runtimeIdentifier in PropertyGroup:
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
Build successfully completes without errors. However when I ran (both debuging or standalone) and application hits Powershell.Invoke, it throws a FileNotFound Exception with message:
"Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified."
1) What am I missing to get all depdendencies in the executable directory?
2) When I add the following to create the single executable
<PublishSingleFile>true</PublishSingleFile>
<UseAppHost>true</UseAppHost>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
It does not get created. I get the executable if I use:
"dotnet publish -r win-x64 -c Debug"
but nothing happens when I run it. (This step used to work fine before PS7)
Is there anthing else I need to do to get the single executable running?
I did some research and figured the following:
Answer 1: There is no Runtime identifer specific Microsoft.Management.Infrastructure.dll files in the runtimes directory. Either Powershell SDK does not support all runtime identifers or its a bug. I will take it to github.
Answer 2: Running the single Executable file is misleading. My expected result was creation of a log file which is created in the application directory. I figured that when the single exe is run, it actually unzips ALL the files to the temp directory and runs the application from there (not the single executable) and hence the log file is not created where the single file executabe is.
To resolve your problem, you have to add this reference to your project. It take me 1 day to found this.
<PackageReference Include="NETStandard.Library" Version="1.6.1" />

MSBuild Exec - All commands exit with MSB3073, exit code 0xC0000005

Windows 10 64-bit - Visual Studio Community 2017
Brand new Hello World C# project.
I added the following to my build tasks:
<Target Name="AfterBuild">
<Message Text="Testing" Importance="high"></Message>
<Exec Command="echo Test" />
</Target>
I see the "Testing" Message executed by the build, so I know the Target is running, at least.
The next task, Exec, always shows the following no matter what commands I give it.
1>$(ProjectPath)(60,5): error MSB3073: The command "echo Test" exited with code -1073741819.
-1073741819 is of course 0xC0000005, Access Violation.
Note: The exact same thing happens if I don't use a Target but instead use post-build commands from the Project Properties GUI (It uses Exec to run those internally, anyway).
Note: I've had similar issues with VS Code somehow misusing my ComSpec variable, which for reference is defined as ComSpec : %SystemRoot%\system32\cmd.exe

How to set LARGEADRESSAWARE in no signing assembly projects for a ClickOnce app?

I have an application with the next two Post-Compilation commands:
call editbin /LARGEADDRESSAWARE $(TargetPath)
call editbin /LARGEADDRESSAWARE $(ProjectDir)obj\$(PlatformName)\$(ConfigurationName)\$(TargetFileName)
and works fine.
But when I publish into a server as the ClickOne Application works with no errors but when I try install in a client the hash of file is different than the value calculated in the manifest.
I tryed to use the next command:
sn -Ra $(ProjectDir)obj\$(PlatformName)\$(ConfigurationName)\$(TargetFileName) PublicPrivateKeyFile.snk
but does not work and it shows the next message:
app.exe does not represent any strong-named assembly.
I suppose it's because all my projects has the "signing the assembly" option with false value. Before using LARGEADDRESSAWARE the ClickOnce Application worked fine.
It is necesary to set the "signing the assembly" option with true value for all projects or are there any way to use LARGEADDRESSAWARE with false value for this option?
EDIT:
Solution of Mark Sowul works fine:
Also I added in AfterBuild the next lines in order to check if the AfterCompile works fine
call "$(VS110COMNTOOLS)vsvars32.bat"
dumpbin /headers "$(TargetPath)" > "$(TargetPath).info"
findstr "(>2GB)" "$(TargetPath).info"
set BUID_ERRORLEVEL=%ERRORLEVEL%
del "$(TargetPath).info"
if [%BUID_ERRORLEVEL%]==[0] echo EXE program updated to use more than 2GB
if [%BUID_ERRORLEVEL%]==[1] echo ERROR: EXE PROGRAM WAS NOT UPDATED TO USE MORE THAN 2GB
set ERRORLEVEL=%BUID_ERRORLEVEL%
Post Build events are too late in the game. You have found this out to an extent, as I did, by realizing you need to alter the file in obj.
However, Post Build occurs after the manifest generation. So editing the obj file there is too late. The better place to do it is in the AfterCompile build target.
You'll have to edit the csproj; add after the lines you'll already see for this:
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
**<Target Name="AfterCompile">
<Exec Command="
call "$(VS110COMNTOOLS)\vsvars32.bat"
editbin /largeaddressaware "$(IntermediateOutputPath)$(TargetFileName)"
" />
</Target>**

PostBuildEvent error copying config file

i am trying to build my project and getting this error:
Error 148 The command "copy "C:\Users\agordon\Documents\Visual Studio 2008\Projects\SubversionRepository\Internal Application\eFormsSystem\eFormsApp\Debug.config" "C:\Users\agordon\Documents\Visual Studio 2008\Projects\SubversionRepository\Internal Application\eFormsSystem\eFormsApp\bin\Debug\eFormsApp.exe.config"
copy "C:\Users\agordon\Documents\Visual Studio 2008\Projects\SubversionRepository\Internal Application\eFormsSystem\eFormsApp\Debug.config" "C:\Users\agordon\Documents\Visual Studio 2008\Projects\SubversionRepository\Internal Application\eFormsSystem\eFormsApp\App.config"" exited with code 1. C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets 3397 13 eFormsApp
here is the compiler generated code for this copying process:
<Target
Name="PostBuildEvent"
Condition=
"
'$(PostBuildEvent)'!=''
and
(
'$(RunPostBuildEvent)'!='OnOutputUpdated'
or
'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'
)
"
DependsOnTargets="$(PostBuildEventDependsOn)">
<Exec WorkingDirectory="$(OutDir)" Command="$(PostBuildEvent)" />
</Target>
the error points to this line:
<Exec WorkingDirectory="$(OutDir)" Command="$(PostBuildEvent)
what am i doing wrong?
For me, the source config file did not exist (I had custom build profile). Once I copied that config file from another known good one and modified it for my environment, everything started working.

Problem with building with csc task in Ant

I have an ant build target using csc:
<target name="compile">
<echo>Starting compiling ServiceLauncher</echo>
<csc optimize="true" debug="true" warnLevel="1"
unsafe="false" targetType="exe" failonerror="true"
incremental="false" mainClass = "ServiceLauncher.Launcher"
srcdir="ServiceLauncher/Launcher/"
outputfile="ServiceLauncher.exe" >
<reference file="libs/log4net.dll"/>
<define name="RELEASE"/>
</csc>
</target>
When I run it, the following exception comes up:
csc failed: java.io.IOException: Cannot run program "csc": CreateProcess error=2, The system cannot find the file specified
However, it runs without the exception but never correctly builds the .exe file, when I manually add in an empty ServiceLauncher.exe.
How can I correctly build this .Net project "ServiceLauncher"?
My guess is that csc.exe is not on the execute path.
From the documentation for the csc task:
csc.exe on Windows or mcs on any other platform must be on the execute path, unless another executable or the full path to that executable is specified in the executable parameter

Categories