未为项目设置 OutputPath 属性

构建 Jenkins/MSBuild 解决方案时出现了这个错误

c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483,9): error :
The OutputPath property is not set for project '<projectname>.csproj'.  Please check to
make sure that you have specified a valid combination of Configuration and Platform
for this project.  Configuration='Latest'  Platform='AnyCPU'.  You may be seeing this
message because you are trying to build a project without a solution file, and have
specified a non-default Configuration or Platform that doesn't exist for this project.
[C:\<path>\<projectname>.csproj]

有什么想法吗?

剪辑

我在我的.csproj 文件中有这个

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Latest|AnyCPU'">
<OutputPath>bin\Latest\</OutputPath>
</PropertyGroup>
125654 次浏览

Open up your csproj in a text editor and see if you have a property group section, should look something like this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Latest|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Latest\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

Do you have a 'Latest' build configuration? If not add the above section to the csproj.

To add to what @James said, I found that if I looked at the project Compile properties in VS2013, the Build Output Path was specified. But when I examined the .csproj file directly, the OutputPath element was missing for the relevant build configuration. So in VS I simply made and reversed a minor edit to the output path, saved it, and that kicked the value into the project file, and I was then able to build.

As mentioned by perlyking, rather than editing the csproj XML The following worked for me. Here are the steps I used.

  1. Open the Project Properties.
  2. Select the Build Tab.
  3. Under the Output section, Check that an output path is set. (if not set one, save the project and it should work).
  4. If it is set, click on the "Browse..." button of the output path.
  5. When the folder selection dialog opens, Navigate up one level in the file browser and then re-select the output folder and click the "Select Folder" button.
  6. Save the project properties and it should work.

I got this error only when I was publishing my web project. I had mistakenly selected the wrong build configuration when setting up the publish profile.

In my case this error happened because the output folder included a dot to make it relative to the current directory. The problem was solved by removing the dot.

The offending Build output path was:

.\bin\Output

The problem was solved by changing it to

bin\Output

The build output path can be found in the Build tab of the project properties, and there is a different path for each combination of Configuration and Platform.

I have figured out how it works (without changing sln/csproj properties in VS2013/2015).

  1. if you want to build .sln file:
    1. /p:ConfigurationPlatforms=Release /p:Platform="Any CPU"
  2. if you want to build .csproj file:
      1. notice the "Any CPU" vs AnyCPU
  3. check the code analysis, fxcop, test coverage(NCover) targets, as well as the MSBUILD should be located properly. In my case its:
    1. but it can be different as you can see microsoft has given 6 cmd options to build code base::AMD (with cross plt, x86 & x64 options) and Windows(cross, x86, x64) and that also when code development happened with default JIT (it can be PreJIT ngen.exe, econoJIT)

I think more than this troubleshooting can be handle using power shell + msbuild. May be helpful for someone ...

I had same issue. I have updated my windows platform by using command line. Currently i got updated to windows@5.0.0 version. Then you need to search for file name "SQLite3.UWP.vcxproj". Try to change "v141" to "v140". Currently I am using Visual Studio 2015 professional. If it's Visual Studio 2017, then there is no need to change version in SQLite3.UWP.vcxproj file.

Just had the issue for some service fabric stuff in MSBuild.

First step was right clicking each affected project and pulling up their Properties, selecting the Build tab, then setting the platform target to x64.

Second step was to go into the configuration manager and set each project to also use x64 for Debug and Release.

This was for a VS2017 project.

The OutputPath property is not set for project error message will appear if a Platform environment variable exists (as seems to happen on HP laptops) and the target of MSBuild contains a reference to another Visual Studio project.

After renaming the Platform environment variable my build now works.

It seems the parameter /p:Platform="Any CPU" gets applied to the target solution but doesn't 'carryover' to referenced projects. In my instance, the error message indicated referenced projects were using the environment variable Platform=MCD.

This error is misleading and can be caused by a different issue. Check the entire message:

The OutputPath property is not set for project 'myproject'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='myconfig' Platform='AnyCPU'. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform.

My build configuration was missing this node in the csproj:

<PlatformTarget>AnyCPU</PlatformTarget>

Despite saying AnyCPU was the selected Platform in the dropdown, the actual xml was not there. Adding it fixed the mismatch between the project and the other project it was referencing.

I had two project configs, Debug and Release. When the Release build was used, it was throwing this error. The issue I found was that in the csproj file, the Debug config was near the top and the Release config was all the way at the bottom.

Manually moving the Release build just below the Debug build fixed it.

I'm assuming I did something incorrectly when setting up my build configurations because this doesn't feel like something I should have had to manually adjust.

I was using MSBuild to build multiple .sln files, and had added a new step to build a .csproj file as well, when I encountered this error.

@Saurabh's answer highlighted the root of the problem. However, when fixing it, adding /p:Platform=AnyCPU to the MSBuild Arguments section didn't fix it. I actually needed to update the Platform value on the build step.

All other build steps were using the $(BuildPlatform) variable value (which happened to be "any cpu", with a space in it).

(Had I been building multiple .csproj files, I probably would have created a second variable for the AnyCPU platform.)

Screenshot of Visual Studio Build step

I had the same problem on a few projects. After adding a new configuration to the projects, the PropertyGroup was added at the very end of the Project file.

Moving the PropertyGroup to right after all the other configurations PropertyGroup fixed the issue.

I hope this helps.

I had this witha slightly unusual SLN/CSPROJ file arrangement:

I had project files:

  • A.csproj, with configurations "Dev" and "Production"
  • B.csproj, with configurations "Dev" and "Production"
  • C.csproj, a "common" library used by both A and B with configurations "Dev" and "Production"

And I had SLN files:

  • AC.sln, with configuration "Production" - this is used by jenkins to build project A and the common library
  • BC.sln, with configuration "Production" - this is used by jenkins to build project B and the common library
  • ABC.sln, with configuration "Dev" - this is used by developers in VS to write new code without having to keep opening different solutions (this answer is a simplified view of a 55-project solution)

I'd made an edit to the common library and introduced a dependency on project A. AC.sln would still build in jenkins but BC.sln gave an error saying:

The OutputPath property is not set for project 'A.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='AnyCPU'.

It was initially puzzling because we don't even have a Debug config anywhere in any project; find in files for Debug| turned up 0 hits

ABC.sln that the human developers use in VS would also build fine. Building BC.sln gave an error that A.dll wasn't found

When the circular irresolvable problem of C depending on A was removed, everything started working again

Edit the properties of the project: Make sure "Configuration Properties->General->Output Directory" is not blank. Note, it's not called OutputPath here. You can probably copy the value from Intermediate Directory.

For me the answer was to fix all the projects in Build > Configuration Manager.

If you have some projects where the name or platform does not match the solution configuration, you should change it so they all match.

enter image description here

I encountered the same problems when build TheXTech (https://github.com/Wohlstand/TheXTech/wiki/Building-on-Windows#building-in-visual-studio-201520172019-and-cmake) recently. And finally I found it is a cmake -A issue. The correct arch for 64 bit on windows is x64, not Win64.

For some more reference, see https://cmake.org/cmake/help/v3.16/generator/Visual%20Studio%2016%202019.html#platform-selection, https://cmake.org/pipermail/cmake/2019-April/069379.html.

I was running into this issue while updating an older project with additional project configurations for per-environment config transforms.

It turns out that when the project configurations were added to the csproj file, they were inserted after an Import element which caused the issue.

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ProjectName.Dev|AnyCPU'">
...

Moving the Import element after all the PropertyGroup definitions fixed the problem for me.

Relevant similar case: https://stackoverflow.com/a/31072208/2452820

Go to Solution properties and change the configuration to Any CPU or X64 or X86, and if build is checked uncheck that for what you are getting error for. By default, project build that for build configuration in solution and throw error as mentioned when building the project.