Build mixed projects on Linux using MSBuild 15 fails - msbuild

Can anybody assist me with the following issue I am having? I am trying to build a mixed solution on linux using MSBuild 15. It contains projects that targets netstandard2.0 and then also projects that target .Net 4.6.2
The netstandard2.0 projects build fine, but the projects that target .Net 4.6.2 fails with the following error:
Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore
I am using MSBuild version 15.6.0.0 for Mono and running on Ubuntu 17.10

quick fix: delete the obj/ directory and then rebuild.
The best I've got at the moment is
rm -rf obj ; msbuild /t:restore /t:build

Related

MsBuild failing for .Net Standard project with error "Package System.Security.Cryptography.ProtectedData, version x.x.x was not found"

Project Setup : Mixed framework solution
.Net Framework 4.6.2 projects in solution : 15
.Net Standard 2.0 projects in solution - 1
Development Machine
Visual Studio 2017(15.7.4) : Builds without any errors
Build Server
TeamCity Version 2017.1.3
Build Steps
Nuget Restore(3.4.4)
dotnet Restore
MSBuild( Build Tools 2017), Tools Version 15.0
Build fails with following error in the .net standard 2.0 project : [ResolvePackageAssets] C:\Program Files\dotnet\sdk\2.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198, 5): Package System.Security.Cryptography.ProtectedData, version 4.4.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
What's interesting is I can't find reference or use of System.Security.Cryptography.ProtectedData anywhere in the project. Any help is greatly appreciated.
P.S - Can't use dotnet build, as the solution needs building of licenses.licx files, and the component which builds it (Microsoft.Build.Tasks.LC) is not ported to .Net Core. The suggestion from various posts was to use MsBuild.exe

npm cannot find SDK version from global.json

I'm in the thick of trying to get up-to-speed on asp.net core / npm / react using this as a base project template:
https://github.com/jonmcquade/aspnetcore-react-redux#local-no-docker
I originally ran into troubles once trying this command:
dotnet build -c Release -o ./app
The error I was seeing:
A compatible SDK version for global.json version: [2.1.0] from
[global.json] was not found Did you mean to run dotnet SDK commands?
Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
I had the specific versions in the documentation installed and I have installed the latest versions, both x64 and x86 platforms.
I now also get this error running the npm install command or the dotnet --version command, yet I have SDKs installed.
It feels like the machine configuration has become broken somehow. I seem to have gotten into a bit of a version pickle trying to get the dotnet build command working and now even NPM isn't working.
Global.json is:
{
"sdk": { "version": "2.1.0" }
}
And the .csproj file contains:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.0-preview1-26216-03</RuntimeFrameworkVersion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<IsPackable>false</IsPackable>
<AssemblyName>FlightSearch</AssemblyName>
<RootNamespace>FlightSearch</RootNamespace>
<ApplicationIcon>ClientApp\favicon.ico</ApplicationIcon>
<Authors>Jon McQuade</Authors>
<Company>ACME Freelancing, Inc.</Company>
<StartupObject></StartupObject>
<Product>Flight Search</Product>
<Description>ASP .NET Core 2.1 MVC SPA with React and Redux</Description>
<RepositoryUrl>http://github.com/jonmcquade/aspnetcore-react-redux</RepositoryUrl>
<PreserveCompilationContext>true</PreserveCompilationContext>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<OutputType>Exe</OutputType>
<Version>2.1</Version>
</PropertyGroup>
What am I missing to get this working?
Are there some machine configuration issues that I can check? Maybe environment variables? I've tried running a repair using the installers but this doesn't address the issue.
The global.json specifies the SDK version of .NET Core that is being used to build your application. This has little to do with the .NET Core Runtime version that you want to run your application with.
Your application is a netcoreapp2.1, so you are running the .NET Core 2.1 Runtime. The earliest SDK Version for that is 2.1.300.
Since that is the latest .NET Core version, you actually don’t need to use a global.json at all: Just delete the file from your project and the tooling should use the latest version which is 2.1.300-rc1 on your machine.
If you're running into this issue on OSX you can fix the issue thusly:
which dotnet
ls + the output from the previous command
You should now see something like:
/usr/local/share/dotnet/dotnet
The directory that has your dotnet binary should also have a directory called sdk, so for the above example you can run ls /usr/local/share/dotnet/sdk, which should output a directory with your current version number. In my case that is 2.1.403 (there may be a better way to get the version number, but I was unable to run dotnet --version without specifying the correct sdk)
If I now open the global.json file in my app's root directory and change the sdk version to "2.1.403-osx-gs-x64", I should now be able to run dotnet command such as dotnet run from within my project.
Just make sure the required SDK version is installed in your machine. On your error, it's .NET core 2.1.0. You don't need the global.json file anymore.

dotnet bundle not working in .net core mvc application

I try to use bundleconfig.json, which is standard added to the project when I started the project. I read every where they say you have to run
dotnet bundle
But this is not working for me I get the error
No executable found matching command "dotnet-bundle"
Now I Googled and found that I have to add this in Project.json
"tools": {
"BundlerMinifier.Core": "2.2.281",
But I have no Project.json file only csproj. I thought I have to install package. So I installed BundlerMinifier.Core but still same error.
What do I have to do so I can run the code and bundle my files?
According to https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-2.1&tabs=netcore-cli%2Caspnetcore2x you have to install the CLI tools for dotnet to do this.
From a command line in the project directory it looks like you do this:
dotnet add package BuildBundlerMinifier
dotnet build
and you should get this result
Microsoft (R) Build Engine version 15.4.8.50001 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Bundler: Begin processing bundleconfig.json
Bundler: Done processing bundleconfig.json
BuildBundlerMinifierApp -> C:\BuildBundlerMinifierApp\bin\Debug\netcoreapp2.0\BuildBundlerMinifierApp.dll
The linked page also talks about ad-hoc bundling. Its on the microsoft site so it shouldn't go anywhere.

Building asp.net core in Teamcity failing with dependencies

I am new to the DevOPs field. I am trying to build a .netcore project using teamcity which is failing with dependencies errors. The dependency System.Diagnostics.Contracts >= 4.0.1 could not be resolved. The dependency System.Net.WebSockets >= 4.0.0 could not be resolved. The dependency System.Runtime.Serialization.Primitives >= 4.1.1 The dependency System.Text.Encodings.Web >= 4.0.0 could not be resolved. I talked to one of the colleagues and he suggested to install the nugget packages but the solution is building on my and the devs system but is failing by Teamcity. how can I install the dependencies on teamcity. In Asp.net the nugget package management is done automatically(some one told me) So how to do it in .netcore.
found out that the terminology is called package restore and in dotnet core it is done by running
dotnet restore
from the directory where the project.json is located or the directory can be passed an an argument as well. After the restore there is no need to run msbuild. build can be done using
dotnet build
The new problem that I am facing now is that after the build and publishing the output folder to Azure web app I am unable to run my dot net core project as to run the project I need to run the command
dotnet nameoftheproject.dll
but I dont know how to run this command using teamcity after publish.

Building .NET Core 1.0 RC2 app on the build server

I've updated my app from DNX, ASP.NET 5 RC1 to ASP.NET Core 1.0 RC2.
Locally it builds and runs fine.
On the build server, I don't have Visual Studio installed, and the build fails with:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I did install the: .NET Core SDK for Windows.
Trying to install the VS 2015 tooling preview fails with:
What would be the correct setup to build .NET Core 1.0 RC2 app on the build server without having to install Visual Studio 2015?
Note: The build box (TeamCity 9) builds/runs tests fine for .NET 4.5 and DNX.
https://learn.microsoft.com/en-us/dotnet/articles/core/windows-prerequisites#issues
Issues
You may be blocked from installing the .NET Core Tooling Preview 2 for Visual Studio 2015 installer due to a temporary bug. To workaround it, run the installer from the commandline with the SKIP_VSU_CHECK=1 argument, as you see in the example below.
DotNetCore.1.0.0-VS2015Tools.Preview2.exe SKIP_VSU_CHECK=1
I'm able to build the solution now. Still can't publish though.
I just copied all the new MSBuild stuff to the build server. I copied:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\
From my local computer to the build server. That includes the new DotNet sub-folder, which contains:
Microsoft.DotNet.Common.targets
Microsoft.DotNet.Extensions.targets
Microsoft.DotNet.props
Microsoft.DotNet.Publishing.targets
Microsoft.DotNet.targets
Microsoft.DotNet.Tasks.dll
Microsoft.VisualStudio.ProjectSystem.DotNet.Runtime.dll
Newtonsoft.Json.dll
I can build the Solution (without the publish arguments) it fails when I try:
MSBuild.exe Solution.sln /p:DeployOnBuild=true /p:publishprofile=local
You can build and test you project via the command line - so there is no need to have Visual Studio installed. By using build steps of type "Command Line" you can run: dotnet restore, dotnet build, dotnet test
Here you can find some description how to run that as a build on TFS. It is written for the hosted TFS but works on-premise as well (and is not only meant for azure as the name of the document might imply):
https://www.visualstudio.com/en-us/docs/build/apps/aspnet/aspnetcore-to-azure
For the pubsishing I have used msdeploy with RC1 but have not yet migrated my deployment build. I might document it here when this is done within the next days.
So without Visual Studio or Web Deploy, my TeamCity build is comprised of 4 builds steps:
dotnet restore
dotnet build
dotnet test
dotnet publish -c Release
I run dotnet test on all projects with a basic for loop.