question

BashirObaid-4387 avatar image
0 Votes"
BashirObaid-4387 asked cooldadtx edited

MSBUILD : error MSB1009: Project file does not exist

I am trying to build an asp.net using Jenkins and Nuget tool and but I got the error" MSBUILD : error MSB1009: Project file does not exist"

C:\ProgramData\chocolatey\bin\nuget.exe restore MyProject.sln -msbuildpath "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"


/p:Configuration=Release /p:RunOctoPack=true /p:OctoPackEnforceAddingFiles=true /p:OctoPackPackageVersion=1.0.$BUILD_NUMBER


C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace\bash>C:\ProgramData\chocolatey\bin\nuget.exe restore MyProject.sln -msbuildpath "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
Using Msbuild from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin'.
All packages listed in packages.config are already installed.

C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace\bash>exit 0
Path To MSBuild.exe: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe
Executing the command cmd.exe /C " chcp 1252 & "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe" /p:Configuration=Release /p:RunOctoPack=true /p:OctoPackEnforceAddingFiles=true /p:OctoPackPackageVersion=2.0.46 MyProject.sln " && exit %%ERRORLEVEL%% from C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace\bash
[bash] $ cmd.exe /C " chcp 1252 & "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe" /p:Configuration=Release /p:RunOctoPack=true /p:OctoPackEnforceAddingFiles=true /p:OctoPackPackageVersion=2.0.46 MyProject.sln " && exit %%ERRORLEVEL%%
Active code page: 1252
Microsoft (R) Build Engine version 16.11.0+0538acc04 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1009: Project file does not exist.
Switch: MyProject.sln
Build step 'Build a Visual Studio project or solution using MSBuild' marked build as failure
Finished: FAILURE

Any help? Thank you

vs-msbuild
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered cooldadtx edited

You're using a relative path to the solution file (`MyProject.sln`) but it is being run from a command prompt which is running from`%SYSTEMROOT%` hence it cannot find the file. Specify the full path to the solution file or, alternatively, ensure the working directory is set to the path to the solution file before running the build command.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I've Modified the below step in Jenkins, but still get the same error


C:\ProgramData\chocolatey\bin\nuget.exe restore "C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace\bash\MyProject.sln" -msbuildpath "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"

0 Votes 0 ·
cooldadtx avatar image cooldadtx BashirObaid-4387 ·

The error you originally reported wasn't on the nuget restore call but the msbuild call.

C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace\bash
[bash] $ cmd.exe /C " chcp 1252 & "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe" /p:Configuration=Release /p:RunOctoPack=true /p:OctoPackEnforceAddingFiles=true /p:OctoPackPackageVersion=2.0.46 **MyProject.sln** " && exit %%ERRORLEVEL%%

Use the full path the SLN file here.

0 Votes 0 ·

"Use the full path the SLN file here"

Sorry but, what do you mean?

add the sln path before the msbuild command?

0 Votes 0 ·
Show more comments
cooldadtx avatar image cooldadtx BashirObaid-4387 ·

I should also point out that it appears you're cloning and building your app from %SYSTEMROOT% which is likely because you're running Jenkins as a service. I know nothing about Jenkins but I'm willing to bet that you are not specifying a path when you clone/download your source code and it is defaulting. You should absolutely not being trying to download/modify/build code from %SYSTEMROOT%. This is a protected directory structure for the OS only. Your build process should be cloning/downloading your code to a temporary location such as c:\source or c:\projects or something just like you do on your own system. This has several advantages:

  • Security: only admins (which include services running as SYSTEM) has write access (and in some cases read access) to the folders under here and therefore should never be used to store user files like projects.
    • Reduces the path length. While Windows supports long file paths some tools may still limit to old value so having many root level folders (e.g. C:\windows\system32\...) is taking up space over something simple like c:\projects

    • Putting all your projects into a root folder makes it line up more with how your local builds work

    • Putting all your projects into a root folder makes it easier to see what has been built and get to logs if something goes wrong, it also makes cleanup easier over time

While your path is unlikely to be causing you issues right now, at some point I would start pointing figures at the locked down directory when things start to fail for no good reason.




0 Votes 0 ·