Conversation
|
Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
…t file is specified Co-authored-by: baronfel <[email protected]>
…ptions Co-authored-by: baronfel <[email protected]>
|
@copilot is it possible to not emit the temp project at all and use purely in-memory virtual projects? |
…ched by synthetic path Co-authored-by: baronfel <[email protected]>
Yes! Implemented in commit 851424b. The approach:
No temp file is created or deleted anywhere. |
|
@copilot try to add some tests for this feature now - for project builds that do a |
…-register after cache clear; add tests Co-authored-by: baronfel <[email protected]>
…ithStdinProject Co-authored-by: baronfel <[email protected]>
Added tests and fixed the
Three tests added:
|
Enables piping MSBuild project content directly via stdin, eliminating the need for a physical project file on disk:
Context
Users should be able to create a text model of a project, pipe it to stdin, and have MSBuild build it directly — without requiring a project file on disk.
Changes Made
src/MSBuild/XMake.csCanRunServerBasedOnCommandLineSwitches: returnsfalsewhenConsole.IsInputRedirected— the MSBuild server process cannot access the client's stdinProcessCommandLineSwitches: when no project is explicitly specified and stdin is redirected, reads all stdin content; if non-empty, stores it ins_stdinProjectContentand setsprojectFileto a synthetic display path (stdin.projin the current working directory) — no file is written to diskBuildProject: after theProjectCollectionis created, parses the stored stdin XML into an in-memoryProjectviaLoadStdinProject, which registers theProjectRootElementin theProjectRootElementCacheunder the synthetic path. All subsequent code paths (preprocess, targets listing, main build, restore) callLoadProject(projectFile, …)or createBuildRequestData(projectFile, …), producing a cache hit that returns the in-memory project without any disk I/O.BuildProject: setsNodeAffinity.InProcviaparameters.HostServicesfor the stdin project, ensuring it always builds on the central in-proc node — worker nodes run in separate processes and cannot access the in-memoryProjectRootElement.BuildProject(restore path): afterExecuteRestorecallsClearCachesAfterBuild(which wipes the entireProjectRootElementCache), the code unloads the oldProjectand callsLoadStdinProjectagain to re-register the project in the now-empty cache before the subsequent default build starts.Executeevaluation path: the--getProperty/--getItemcode path creates its ownProjectCollection, so it re-parses the content froms_stdinProjectContentviaLoadStdinProjectdirectly.Executefinallyblock: clearss_stdinProjectContent = null— no temp file to deletes_stdinProjectContentstatic field to store the piped XML content across callsLoadStdinProjecthelper method to avoid duplication of the XML-parse +FullPath-assignment logicsrc/MSBuild.UnitTests/XMake_Tests.csBuildProjectPipedViaStdin: end-to-end test spawning MSBuild as a subprocess with project XML piped to stdin, asserting successful build and expected outputBuildProjectPipedViaStdin_WithRestore: end-to-end test for the-restore+ default build path, asserting both theRestoreandBuildtargets ran — exercises the cache re-registration fixBuildProjectPipedViaStdin_SpecificTarget: end-to-end test for an explicit-t:TargetinvocationRunMSBuildWithStdinProject: shared helper that spawns the MSBuild subprocess and pipes project XML to stdin, used by all three testsTesting
Three E2E tests spawn MSBuild as a subprocess with project XML piped to stdin:
-restoreruns theRestoretarget and the subsequent default build still finds the in-memory project after the cache is cleared-t:Targetworks with piped projectsExisting
ProcessProjectSwitchtests and response-file implicit discovery tests continue to pass unmodified — stdin is only read whenprojectParameters.Length == 0 && Console.IsInputRedirectedand the content is non-empty.Notes
/dev/nullstdin falls through to the normal "find a project in the current directory" behavior.ProjectRootElementregistered in theProjectRootElementCacheunder the synthetic pathstdin.projin the current working directory. Relative paths inside the piped project content resolve relative to the current working directory, matching expected behavior.NodeAffinity.InProc. After a-restoreclears the cache, the project is automatically re-registered before the main build begins.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.