Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't MSBuild build a project with a dot in the name?

Tags:

The Story So Far

I've got a nice solution with a desktop application project, a few library projects, and a couple of development tools projects (also desktop applications). At the moment, my build server outputs all of the code into one OutputPath. So we end up with

drop-x.y.z\     Company.MainApplication.exe      <-- main application      Company.MainApplicationCore.dll  <-- libraries     Helper.exe                       <-- developer tools     Grapher.exe     Parser.exe     ...                              <-- the rest of the output 

But, we're growing up and people outside of our team want access to our tools. So I want to organize the output. I decided that what we would want is a different OutputPath per executable project

drop-x.y.z\   Company.MainApplication\     Company.MainApplication.exe      <-- main application      Company.MainApplicationCore.dll  <-- libraries     ...                              <-- application specific output   Helper\     Helper.exe                       <-- developer tools     ...                              <-- tool specific output   Grapher\     Grapher.exe     ...   Parser\     Parser.exe     ... 

What I Did

I found this simple command. I like it because it retains all the Solution working-dir context that makes msbuild a pain.

msbuild /target:<ProjectName> 

For example, from my solution root as a working directory, I would call

PS> msbuild /target:Helper /property:OutputPath="$pwd\out\Helper" 

I'm testing this from PowerShell, so that $pwd resolves to the full path to my working directory, or the Solution root in this case. I get the output I desire.

However, when I run this command

PS> msbuild /target:Company.MainApplication /property:OutputPath="$pwd\out\Company.MainApplication" 

I get the following error output (there's no more information, I ran with /verbosity:diagnostic)

The target "Company.MainApplication" does not exist in the project.


What I Need

The command fails on any project with a dot or dots in the name. I tried with many combinations of working directories and properties. I tried several ways of escaping the property values. I also tried running the command from a <Task> in a targets file.

I need to know either
A) How to fix this command to work property
B) How to achieve the same output with minimal friction

like image 502
Anthony Mastrean Avatar asked May 02 '11 22:05

Anthony Mastrean


People also ask

How do I create a project using MSBuild command line?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

How do I enable MSBuild?

In the Visual Studio installer, navigate to Individual Components, and locate the checkbox for MSBuild. It is automatically selected when you choose any of the other workloads to install. To install MSBuild on a system that doesn't have Visual Studio, go to Build Tools for Visual Studio 2022 on the downloads page.

How do you check MSBuild is installed or not?

MSBuild is now installed in a folder under each version of Visual Studio. For example, C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild . You can also use the following PowerShell module to locate MSBuild: vssetup. powershell.


1 Answers

Try using an underscore as an escape character for the dot in the target parameter, e.g.

msbuild /target:Company_MainApplication /property:OutputPath="$pwd\out\Company.MainApplication" 
like image 50
Dan Nolan Avatar answered Dec 16 '22 04:12

Dan Nolan