Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:54:55+00:00 2026-06-07T14:54:55+00:00

I am wondering if there is simple way to ensure that: when a C#

  • 0

I am wondering if there is simple way to ensure that: when a C# project is compiled, the Csc.exe launched inherits the parent processor affinity settings; or perhaps a way that I can supply this.

I have been trying to accomplish this by launching a bat file from VS.NET cmd prompt:

start /affinity 01 custombuild.cmd

Inside my custombuild.cmd I have:

@echo off
msbuild Libraries.sln /t:rebuild /p:Configuration=Release;platform=x64 /m:1
:END

The command line call to Csc.exe that is generated looks like the following:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe ... (the rest omitted for brevity.)

I’d like Csc.exe to inherit the processor affinity, or a simple way to be able to override how Csc.exe call is generated so that it becomes:

start /affinity 01 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe ... (the rest omitted for brevity.)

I also noticed that CoreCompile target is defined in Microsoft.CSharp.targets, should I be considering overriding MSBuildToolsPath variable so I can sneak in my own version. This feels rather hacky. Any help would be much appreciated.

Status Update:
I have worked out that the csc.exe process launched by csc task is actually prepared in ExecuteTool method of the Task class’s member and i have created a custom task CpuAffineCscTask which derives from the Csc and overrides ExecuteTool method. My goal is to launch the csc.exe using a pinvoke call to CreateProcess in suspended state, then set affinity and then resume the thread. I also used reflection to make the state of various variables is correctly set etc. Now i am trying to override the CoreCompile target the one which is defined in MicrosoftCSharp.targets file but when my target runs i get the following runtime error. Are there any known examples of this around ? Even though the whole cmd correctly prints out in the msbuild diagnostic output. The diagnostic output follows for your consideration.

Task “MSBuild.Tasks.CpuAffineCscTask” (TaskId:14)
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /unsafe+ /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /doc:..\Bin\Release\Ugp.Igt.Core.XML /define:TRACE /reference:”C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll” /reference:”C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll” /reference:”C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\WindowsBase.dll” /debug:pdbonly /filealign:512 /keyfile:..\StrongNameKeyFile.snk /optimize+ /out:obj\Release\Ugp.Igt.Core.dll /target:library ..\DevelopmentKitVersionInfo.cs AnonymousDisposable.cs ByteArrayExtensionMethods.cs TypeMustImplementMethodAttribute.cs WeakEvent.cs “C:\Users\bhatiah\AppData\Local\Temp.NETFramework,Version=v4.0.AssemblyAttributes.cs” (TaskId:14)
E:\source\Core\Microsoft.CSharp.targets(217,3): error MSB6001: Invalid command line switch for “Csc.exe”. Value cannot be null.
E:\source\Core\Microsoft.CSharp.targets(217,3): error MSB6001: Parameter name: SafeHandle cannot be null.

Done executing task “Igt.MSBuild.Tasks.CpuAffineCscTask” — FAILED. (TaskId:14)
Done building target “CoreCompile” in project “Igt.Core.csproj” — FAILED.: (TargetId:37)
Target “_CheckForCompileOutputs: (TargetId:38)” in file “c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets” from project “E:\source\Core\Igt.Core\Igt.Core.csproj” (target “_CleanGetCurrentAndPriorFileWrites” depends on it):

Any help would be very much appreciated.

PS: I am redirecting all three IO streams since i am using CreateProcess and pipes but post creation i use Process.getProcessById .net method to get a reference to the process object and attach the handlers.


hardy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:54:56+00:00Added an answer on June 7, 2026 at 2:54 pm

    Get the command string by overriding the executeTool method, preappend it with start /affinity 01 write it out to a batch file in the same folder as the csproj file, use shellexecute method to run it. (might need to ensure all the output directories exist).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there is a simple way in Perl to ensure that
Just wondering if there is a simple way to have an alert that can't
I am wondering if there is a simple way to allow a JQuery datatable
Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a good way to generate temporary URLs that expire in
just wondering if there is a simple way in java to display the contents
I was wondering if in python there was a simple way to run code
I'm tooling around with Django and I'm wondering if there is a simple way
I'm wondering if there's a simple way for a Word macro to determine which
I was wondering if there's a simple way to parse command line options having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.