153

Why am I getting the following Build error?

C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe C:\Code\EduBenesysNET\EduBenesysNET\EduBenesysNET.vbproj /t:publish /p:Configuration=Release /p:Platform=AnyCPU /v:detailed /p:PublishDir="\\BSIIS3\c$\DATA\WEBSITES\benesys.net\benesys.net\TotalEducationTest\"  /p:InstallUrl="https://www.benesys.net/benesys.net/TotalEducationTest/"  /p:ApplicationVersion=1.0.1.198  /p:ProductName="Total Education TEST"   /p:PublisherName="BeneSys, Inc."  /p:UpdateRequired="True"  /p:MinimumRequiredVersion=1.0.1.198
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3603]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

MSBUILD : error MSB1008: Only one project can be specified.
Switch: Education

For switch syntax, type "MSBuild /help"

I do not see how a second project is being specified.
Is it stored in a project file somewhere?

Zitrax
  • 19,036
  • 20
  • 88
  • 110
Gerhard Weiss
  • 9,343
  • 18
  • 65
  • 67
  • 5
    The very same command works in powershell but not in cmd.exe... looks like you are hitting a spacial character sequance somewhere... – Cédric Rup Jan 29 '11 at 08:25

24 Answers24

152

It turns out the trailing slash in the PublishDir property is escaping the end quote. Escaping the trailing slash solved my problem.

/p:PublishDir="\\BSIIS3\c$\DATA\WEBSITES\benesys.net\benesys.net\TotalEducationTest\\"

This way we can use quotes for paths that have whitespace in properties that MSBuild requires the trailing slash.

I know this is an old post, but I feel like I needed to share this with someone :-)

Matt
  • 1,871
  • 2
  • 11
  • 5
55

On Git Bash I had to specify the parameters with double slashes like:

MSBuild.exe "Path\to\Solution.sln" //p:Platform="x86" //p:Configuration=Release //p:AppxBundlePlatforms="x86" 
friday
  • 1,358
  • 1
  • 14
  • 23
  • 1
    Look like this is the root cause, related on how Git_Bash works on POSIX path starting with a slash putting in the mix the windows style paths Double slashes solve or you can disable automatic path conversion to keep interoperability history: http://www.mingw.org/wiki/Posix_path_conversion Release notes https://github.com/git-for-windows/build-extra/blob/a9090580ee37686a53166796dffda531041e16f8/ReleaseNotes.md – Wolfium Oct 25 '20 at 15:47
  • 4
    Alternatively, you can use `-p` instead of `/p`. – parched Feb 28 '22 at 02:51
  • `-p` works for me also – Mehdi Hadeli Feb 01 '23 at 14:16
49

SOLUTION
Remove the Quotes around the /p:PublishDir setting

i.e.
Instead of quotes

/p:PublishDir="\\BSIIS3\c$\DATA\WEBSITES\benesys.net\benesys.net\TotalEducationTest\"  

Use no quotes

/p:PublishDir=\\BSIIS3\c$\DATA\WEBSITES\benesys.net\benesys.net\TotalEducationTest\  

I am sorry I did not post my finding sooner. I actually had to research again to see what needed to be changed. Who would have thought removing quotes would have worked? I discovered this when viewing a coworkers build for another solution and noticed it did not have quotes.

Liam
  • 27,717
  • 28
  • 128
  • 190
Gerhard Weiss
  • 9,343
  • 18
  • 65
  • 67
  • 2
    This is very strange. In my case I got the same error but the problem is that I had an unquoted path with a space in it. Adding the quotes fixed the problem. – Mark Arnott Aug 05 '11 at 13:21
  • I had the same issue as @MarkArnott, it did not work with spaces or escaped spaces, but quoting did. – Zitrax Feb 05 '13 at 09:39
  • 9
    Probably the last backslash in your path was escaping the closing double-quote. If correct, then you didn't need to remove the double-quotes, but instead you needed to escape your backslashes. – Carl G Jan 13 '14 at 16:10
  • 2
    Remember, the spaces in dir path needs to be escaped or have to be placed inside a double quotes – OK999 Aug 09 '16 at 19:10
33

This problem appears when you have a path or a property containing a space and that is not quoted.

All your properties and path have quote around them, it's strange. The error message indicates Education as a switch, try to remove /p:ProductName="Total Education TEST" to see if it works.

Julien Hoarau
  • 48,964
  • 20
  • 128
  • 117
  • 4
    Avoid Space in folder path to get rid of this issue. – Gopinath Sep 22 '12 at 19:31
  • 1
    @Julien Hoarau: I tried `MSBuild.exe C:\BuildAgent\work\4c7b8ac8bc7d723e\WebService.sln /p:Configuration=Release /p:OutputPath=bin /p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MsDeployServiceUrl=https://204.158.674.5/msdeploy.axd /p:username=Admin /p:password=Password#321 /p:AllowUntrustedCertificate=True /p:DeployIisAppPath=Default WebSite/New /p:MSDeployPublishMethod=WMSVC`. It gives me an error `MSBUILD : error MSB1008: Only one project can be specified. Switch: WebSite/New`. What might be the issue? – Nevin Raj Victor May 27 '15 at 14:58
  • @NevinRajVictor A lot late, but probably you should put quotes around `Default WebSite/New` – Anderson Pimentel Mar 31 '20 at 20:53
11

You need to put qoutes around the path and file name.
So use MSBuild "C:\Path Name\File Name.Exe" /[Options]

user229044
  • 232,980
  • 40
  • 330
  • 338
Zamir
  • 111
  • 1
  • 2
4

Try to remove the trailing backslash or slash at the end of you publish path and install url

/p:PublishDir="\\BSIIS3\c$\DATA\WEBSITES\benesys.net\benesys.net\TotalEducationTest"
/p:InstallUrl="https://www.benesys.net/benesys.net/TotalEducationTest"

You must have hit a special sequence of characters with the \" and (or) /", but I don't know enough in cmd.exe to figure out.

I personnaly always use Powershell : it's way more friendly and powerful!

Hope it helps!

Cédric Rup
  • 15,468
  • 3
  • 39
  • 30
4

Yet another cause and solution to this: Check that you didn't put a space in the wrong place, i.e. in parameters; mine was dotnet -c Release - o /home/some/path (note the space between - and o), I kept looking at the path itself, which was correct and threw me off. Hope that helps! (this was in Bash though it should also apply to Windows)

Christian Rondeau
  • 4,143
  • 5
  • 28
  • 46
3

In vs2012 just try to create a Build definition "Test Build" using the default TFS template "DefaultTemplate....xaml" (usually a copy of it)

It will fail with the usual self-explaining-error: "MSBUILD : error MSB1008: Only one project can be specified.Switch: Activities"

Off course somewhere in the default TFS template some " are missing so msbuild will receive as parameter a non escaped directory containing spaces so will result in multiple projects(?!)

So NEVER use spaces in you TFS Build Definition names, pretty sad and simple at the same time

Damien Overeem
  • 4,487
  • 4
  • 36
  • 55
3

I was using single quotes around the password parameter when I got the error

/p:password='my secret' bad

and changed it to use double quotes to resolve the issue.

/p:password="my secret" good

Likely the same would apply to any parameter that needs quotes for values that contain a space.

John K
  • 28,441
  • 31
  • 139
  • 229
3

For me I had forgot to add closing quote

/p:DeployOnBuild=true;OutDir="$(build.artifactstagingdirectory)

to

/p:DeployOnBuild=true;OutDir="$(build.artifactstagingdirectory)"

Reza
  • 18,865
  • 13
  • 88
  • 163
3

If you are using Azure DevOps MSBuild task the error may be caused by doubled configuration flag. Please make sure you put $(BuildConfiguration) in specified box instead of MSBuild Arguments one: enter image description here

J.Wincewicz
  • 849
  • 12
  • 19
2

In my case, it was the switches. I resolved it by using -p instead of /p.

Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63
1

This worked for me in TFS MSBuild Argument. Note the number of slashes.

/p:DefaultPackageOutputDir="\\Rdevnet\Visual Studio Projects\Insurance\"

Mark Monforti
  • 463
  • 4
  • 8
1

If you use default workspace in Jenkins, this might occur. Use custom workspace location without any spaces.

enter image description here

liberforce
  • 11,189
  • 37
  • 48
1

For future readers.

I got this error because my specified LOG file had a space in it:

BEFORE:

/l:FileLogger,Microsoft.Build.Engine;logfile=c:\Folder With Spaces\My_Log.log

AFTER: (which resolved it)

/l:FileLogger,Microsoft.Build.Engine;logfile="c:\Folder With Spaces\My_Log.log"
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
1

If you are using Any CPU you may need to put it in single quotes.

Certainly when running in a Dockerfile, I had to use single quotes:

# Fails. Gives: MSBUILD : error MSB1008: Only one project can be specified.
RUN msbuild ConsoleAppFw451.sln /p:Configuration=Debug /p:Platform="Any CPU" 

# Passes. Gives: Successfully built 40163c3e0121
RUN msbuild ConsoleAppFw451.sln /p:Configuration=Debug /p:Platform='Any CPU' 
Badgerspot
  • 2,301
  • 3
  • 28
  • 42
1

For me adding the path to the solution file in double quotes solved the issue. One of the folders in the path had a blank space in the name and this caused it to consider 2 solution files instead of one. I executed in the following was and it worked.

MSBuild.exe "C:\Folder Name With Space\Project\project.sln"

Vinit Divekar
  • 774
  • 10
  • 24
1

In my case:

dotnet build -c Release --no-restore -p:Version=${VERSION} -p:Description=${DESCRIPTION}

I had this error:

MSBUILD : error MSB1008: Only one project can be specified.

But I changed it:

-p:Description=${DESCRIPTION}

to

-p:Description="${DESCRIPTION}"

And works.

0

Just in case someone has the same issue as me, I was missing "/" before one of the "/p" arguments. Not very clear from the description. I hope this helps someone.

Johnny
  • 2,503
  • 6
  • 21
  • 22
0

I did use solution given in https://www.codingdefined.com/2014/10/solved-msbuild-error-msb1008-only-one.html and that solves the issue. All we need to do is check spaces and ''(check backslashes) in the command

Anusha M Shetty
  • 379
  • 3
  • 4
0

I ran into this issue with a very simple command, which didn't include any quote, any space, any slash, anything strange at all.

I was using MINGW64 shell.

The same exact command from PowerShell worked instead.

o0'.
  • 11,739
  • 19
  • 60
  • 87
0

With .NET 6 CLI, I face the "MSBUILD : error MSB1008: Only one project can be specified." when running the test command with -d

Not Work

 dotnet test Abc.Tests.csproj -d "verbose_log.txt"

Work

 dotnet test Abc.Tests.csproj -d="verbose_log.txt"
 dotnet test Abc.Tests.csproj -d:"verbose_log.txt"
 dotnet test Abc.Tests.csproj --diag "verbose_log.txt"
Hieu Le
  • 1,042
  • 8
  • 18
0

Old thread with a lot of answers ... anyway, my solution was to write out /property (instead of only using /p).

E.g.:

dotnet publish path/to/project/ -c Release /property:AssemblyVersion=1.2.3.4 /property:Version=1.2.3.4-alpha -o path/to/out/folder
nilsK
  • 4,323
  • 2
  • 26
  • 40
0

In my case it was because I'd combined multiple commands eg: "clean publish". Can't blame me for trying porting Gradle and Maven CLI practices to Dotnet CLI.

Godfred
  • 91
  • 8