Need to msbuild C# project of lower version on commandline, without Visual Studio - c#

I need to msbuild C# project of lower version on commandline, I donot have Visual Studios.
I am facing the error while building the project:
Microsoft (R) Build Engine Version 2.0.50727.42
[Microsoft .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation 2005. All rights reserved.
.\Project.sln : Solution file error MSB4054: The solution file must be opened in t
he Visual Studio IDE and converted to the latest version before it can be built
by MSBuild.
I have the .sln file and previously someone did build the project from here possibly with the Version 1.0 engine.
Can someone help me with this?

You'll find MSBuild in C:\Windows\Microsoft.NET\Framework[framework version].
For instance, the one that came with .NET 2.0 is in C:\Windows\Microsoft.NET\Framework\v2.0.50727. I believe that's the one that came with VS 8.0.
If you need the x64 version, it's in C:\Windows\Microsoft.NET\Framework64\v2.0.50727

In many cases you can just pass the project file to MsBuild and it will compile just fine. Forexample:
msbuild MyProj.csproj /p:Configuration=Release
.csproj files are valid MsBuild XML files whereas .sln files have to be converted into MsBuild scripts on the fly, which is why they are tied to a specific version of Visual Studio.
If you have multiple projects in your solution I would recommend passing the primary/startup project to MsBuild so that all of the dependencies also get built. This method does not always work and you may run into problems is if you have any solution level dependencies or custom solution configurations specified in the solution file.

Ok, got permission from client to install VStudios. Installed and built the program :/

Related

Visual Studio 2019 shows an empty solution after creating a .NET Core project

When I create a new .NET Core project in Visual Studio 2019, it shows only the solution file. Other files are not showing and also I am not able to debug or the project.
I've also run into this problem and after two days of searching forums and reading .NET documentations, I finally managed to find the solution.
The problem is that Visual Studio cannot find the proper SDK version. There might be a few reasons for this, but first of all, check if you have any SDK installed:
Open the Command Prompt:
Start Menu > Visual Studio 2019 > Developer Command Prompt for Visual Studio 2019
Run the command: dotnet --info
Case 1:
The .NET SDKs installed: section says that you have no SDKs installed.
-OR-
A .NET SDK is installed but not for the right architecture (this was my case), meaning that you had installed x86 version instead of x64.
Solution:
Uninstall all versions of .NET Core SDKs and Runtimes, then download and install the latest x64 SDK and Runtime version from Microsoft's webpage.
Case 2:
A .NET SDK is installed but the referenced SDK version in the current project's .csproj file does not match the installed version nor the one specified in the global.json (if exists).
Solution: Edit the .csproj file, so that the SDK versions match.
If you have or need a global.json file, make sure you set its content properly. You can read more about it here.
Finally
Don't forget to open Visual Studio, create a new e.g. Console Application and see if the Solution's files appear in the Solution Explorer window (they should). Note that existing projects may still not be working properly because their .csproj file might have wrong SDK reference - if so, you have to fix them manually.

Azure Pipeline deploy to Web App Service failing with Missing required property 'OutputPath'

I am running into an issue with deploying to Azure Web App resource I've got set up. I can't find much about this error online so posting here...
I have a .NET solution with a main project and several class library projects which i make references to in my main project.
For some reason, the deployment is failing because it doesn't pick up those dll projects in the solution. My code is on a bitbucket repo and I've set it to deploy to my web app resource whenever I make a commit to a certain branch.
But it is failing with this error:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin\amd64'.
All packages listed in packages.config are already installed.
Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'. Input files: D:\home\site\repository\XXXCode\XXXXX.Entities\XXXXX.Entities.csproj.
Failed exitCode=1, command=nuget restore "D:\home\site\repository\XXXCode\XXXCode.sln"
An error has occurred during web site deployment.
Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'. Input files: D:\home\site\repository\XXXCode\XXXXX.Entities\XXXXX.Entities.csproj.\r\nD:\Program Files (x86)\SiteExtensions\Kudu\82.10503.3890\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
Am i missing a step here?
I'm new to this so I probably forgot a step somewhere.
Any help greatly appreciated, thanks!
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program
Files (x86)\MSBuild\14.0\bin\amd64'.
According to this error message, apparently the version you are using is MSBuild 14.0(VS 2015 tools).
And also, from this message:
Missing required property 'OutputPath' for project type
'PackageReference'.
As far as I understood, the PackageReference just works with MSBuild version 15 and higher, instead of 14.0. Since it came with VS 2017, and at the same time MSBuild 15.0.
So, for solve this error, I recommend you try with the newer version: MSbuild 15.0.
You can also refer to this ticket: Missing required property 'OutputPath' for project type 'PackageReference'
Edit:
First, please ensure that your script can be executed successfully in VS2017 locally.
And then, if you build with Visual Studio build task, change the Visual Studio Version as:
Or, if its MSBuild task you are using, just need to change the MSBuild Version:
On the other hand, if you are using Specify Location instead of Version in MSbuild task, specify the location path of MSBuild.exe which under MSBuild 15.0. For me, I am using VS2019, so the location of MSbuild 16.0 is:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe
Update:
Since you are using VS2017, you can specified the location of MSbuild 15.0 with your MSbuild 15.0 file path as:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64

MSBUILD used in from wrong location in VS2017 after uninstalling VS2015? XmlSerializers builds with incorrect versions

I uninstalled VS2017 and VS2015 and only re-installed VS2017. Now, on some asp.net 3.5 assemblies that were previously building/working fine in VS2017 are no longer building correctly.
Even though the project references system.xml v2.0, when it is build, the *.XmlSerializers assembly pulls in the v4.0 version of the assembly. Causing our sites running on the asp.net 2.0 application pool to no longer function.
Here is my assembly Application settings:
Here is my project reference:
And here is Ildasm.exe showing the wrong system.xml pulled in:
The only bindings I have in the web.config are the following:
I'm trying to determine if it is build MSBuild is ran from the C:\Windows\Microsoft.NET\Framework\v4.0.30319 path or what.
UPDATE: I ran a build with detailed output on my desktop (the one that no longer functions properly) and my laptop (which still works). There were obviously lots of differences, but the ones that jumped out as possible issues are:
Laptop (still working)
SDK35ToolsPath = C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\
MSBuildVersion = 15.7.180
TargetFrameworkSDKToolsDirectory = C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\
VSSDK140Install = C:\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\ missing from desktop
Microsoft (R) Visual C# Compiler version 2.8.3.63029 (e9a3a6c0) (TaskId:28)
Desktop (not working)
SDK35ToolsPath =
MSBuildVersion = 15.9.21
TargetFrameworkSDKToolsDirectory = C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\
Microsoft (R) Visual C# Compiler version 2.10.0.0 (b9fb1610) (TaskId:28)
Wonder if I should reinstall VS2015 again as well even though I'll never use the UI?
Copied from the comment.
VS2017/2019 no longer installs .NET Framework 3.5 SDK by default. That's why you saw SDK35ToolsPath is blank in MSBuild logging.
Go to VS2017/2019 installer and select .NET Framework 3.5 development tools to install. Then it should compile without problems.

Using C# 7.1 with MSBuild

To use the new C# 7.1 language features with Visual Studio 2017, you add the setting <LangVersion>latest</LangVersion> to your project file(s).
However, building such projects from MSBuild (version 15.3.409.57025, located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin) results in an error:
CSC : error CS1617: Invalid option 'latest' for /langversion;
must be ISO-1, ISO-2, Default or an integer in range 1 to 6.
Is this feature just not yet supported by MSBuild, or is it possible to get this working?
This covers 200+ projects that were originally created variously in Visual Studio 2013 and 2015. They were all re-targeted to .NET 4.7 using the Target Framework Migrator tool (which saved lots of clicking and appears - based on inspecting .csproj file changes - to do the job correctly).
The projects all build successfully from Visual Studio 2017.
Nuget packages
Microsoft.Net.Compilers nuget package does not work and needn't to be installed.
Set the following project/build settings
Set at least C# 7.1 or higher in the Debug and Release build properties. (via: Project menu > [ProjectName] Properties > Build tab > [Advanced] button > Language Version).
Setting it to latest does not work.
Also make sure that you are running the latest MSBuild version.
Add a reference to the Microsoft.Net.Compilers package (version 2.3.x, to get C# 7.1).
A short description of the package:
Microsoft.Net.Compilers
This package not only includes the C# and
Visual Basic compilers, it also modifies MSBuild targets so that the
included compiler versions are used rather than any system-installed
versions. Once installed, this package requires Microsoft Build Tools
2015.
Make sure you have changed for "All Configuration" and not just "Debug"
else you will be baffling why it is failing at production.
In case you land here because you get the error as the OP mentioned, running msbuild via command line (e.g. from a build agent such as jenkins), the solution may be as easy as to upgrade Microsoft Build Tools 2015.
You can do that via choco install microsoft-build-tools or manually via the official Microsoft Build Tools 2015 or by updating your Visual Studio 2017 installation.
I've got a solution with a C# console app using C# 7.1 here.
Using the VS 2017 command line (and thus MSBuild 15.3.409.57025) it worked fine. (The .csproj does contain <LangVersion>latest</LangVersion>.)
Is this feature just not yet supported by MSBuild, or is it possible to get this working?
Yes it is.
Which instance of csc.exe is being run and what's its version? Because it looks like, despite quoting the version, you have the wrong version of csc.exe (the error message says 1-6 so not even C# 7 would work).
We discovered that our MVC projects were triggering this issue.
To fix, we updated the Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package used by these projects from version 1.0.0 to 1.0.7.

Build Net Framework web application referencing net-standard library with Cake build

I have two projects: NET Standard class library and regular NET Framework web application. Web application references class library.
I use Visual Studio 2017 Preview.
When I try to build the solution with Cake using MSBuild command I get the unsupported project message:
error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the
MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MS
Build 2003 format.
If I try to use DotNetCoreBuild I get:
error MSB4019: The imported project "C:\Program Files\dotnet\sdk\2.0.2-vspre-006949\Microsoft\VisualStu
dio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
But the solution is built successfully by Visual Studio.
Latest MSBuild version has the targets to build NET Standard libraries. The problem is in Visual Studio Preview installation path: Cake can't find the latest MSBuild.
It will also fail if you will try to specify VS2017 in MSBuildToolVersion.
You have to specify the MSBuild executable manually to make it work with VS Preview.
string msBuildPath = #"c:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\15.0\Bin\MSBuild.exe";
MSBuild("../NetStdExample.sln", new MSBuildSettings {
Verbosity = Verbosity.Minimal,
ToolPath = msBuildPath
});
Update by #Gary Ewan Park: there is a tool for determining latest VS install.

Categories

Resources