Run corflags automaticly after build

847 views Asked by At

I build a WPF program for the .NET framework. I need to run the following corflags command in order for the program to work correctly.

corflags c:/[file location]/[file name].exe /32BITREQ+

Now I do this manually trough the visual studio console, but I would like to do that automaticly after a build completed. Is that possible?

I tried to search around for a solution but couldn't find one. My best guess is to use a command in the Post-build event command line. I tried to following.

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\corflags.exe" "$(ProjectDir)bin\$(ConfigurationName)\QardPrint.exe" /32BITREQ+

This gives the following error. in the Output window.

1>Target "PostBuildEvent: (TargetId:81)" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets" from project "H:\VSWorkspace\VSTS\Quantore\LoginQard\QardPrint\QardPrint.csproj" (target "CoreBuild" depends on it):
1>Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>Task "Exec" (TaskId:58)
1>  Task Parameter:WorkingDirectory=bin\x86\Debug\ (TaskId:58)
1>  Task Parameter:Command="C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\corflags.exe" "H:\VSWorkspace\VSTS\Quantore\LoginQard\QardPrint\bin\Debug\QardPrint.exe" /32BITREQ+ (TaskId:58)
1>  "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\corflags.exe" "H:\VSWorkspace\VSTS\Quantore\LoginQard\QardPrint\bin\Debug\QardPrint.exe" /32BITREQ+ (TaskId:58)
1>  Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  4.6.1055.0 (TaskId:58)
1>  Copyright (c) Microsoft Corporation.  All rights reserved. (TaskId:58)
1>   (TaskId:58)
1>corflags : error CF001: Could not open file for writing
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(5019,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\corflags.exe" "H:\VSWorkspace\VSTS\Quantore\LoginQard\QardPrint\bin\Debug\QardPrint.exe" /32BITREQ+" exited with code 1.
1>Done executing task "Exec" -- FAILED. (TaskId:58)

In the error list

Could not open file for writing QardPrint   H:\VSWorkspace\VSTS\Quantore\LoginQard\QardPrint\corflags

Instead of using corflags directly I also tried the following things Hans Passant suggested in the comments.

  • ProjectProperties-->Build-->General-->PlatformTarget: x86
  • ProjectProperties-->Build-->Platform: x86

This did not solve the error I have with an oracle connection (version 9.2). My manual corflags command does solve this issue.

1

There are 1 answers

8
Leo Liu On

This did not solve the error I have with an oracle connection (version 9.2). My manual corflags command does solve this issue.

You need pay attention to the path of QardPrint.exe in your command line after you change Build->General-->Platform target is set to x86 Build-->Platform = x86.

After change platform target to x86, the QardPrint.exe was new generated at x86 folder:

$(ProjectDir)bin\x86\$(ConfigurationName)\QardPrint.exe

If you do not change the previous path in the command line "$(ProjectDir)bin\$(ConfigurationName)\QardPrint.exe", you will get that error. I got the same error with previous command line:

enter image description here

If I correct the path, all thing can works fine.

Hope this helps.