Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

msbuild VS2017 solution with netstandard library in it

I have created a VS2017 solution containing a single Example library targeting .NETStandard 1.4

To this I have added a single class:

using System;
namespace ExampleNetstandard
{
    public class Example
    {
        public string A { get; set; }
    }
}

From visual studio it compile fine but if you clear out the bin & obj directories and then build from msbuild using: msbuild ExampleNetstandard.sln /t:Build /p:Configuration=Release /p:Platform="Any CPU"

I get the following error:

C:\Users\Aaron\AppData\Local\Temp.NETStandard,Version=v1.4.AssemblyAttributes.cs(4,20): error CS0400: The type or name space name 'System' could not be found in the global namespace (are you missing an assembly reference?) [D:\src\Example Netstandard\ExampleNetstandard.csproj] obj\Release\netstandard1.4\ExampleNetstandard.AssemblyInfo.cs(6,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [D:\src\ExampleNetstandard\ExampleNets tandard.csproj]

Is there something specific I need to do to get this kind of project to build from msbuild? I'm investigating this as our TeamCity server is throwing up this error on the real project

like image 336
Aaron0 Avatar asked Apr 04 '17 07:04

Aaron0


1 Answers

If you blow away your bin, and obj directories you will need to restore your packages again. When you run dotnet restore there are some files emitted inside your obj directory you need for compilation. Also you should stick with the dotnet cli for dotnet core projects. Since the dotnet cli ships with the proper versions of msbuild for core.

You can restore your packages by running dotnet restore and then run dotnet build -c Release to compile your app. Anytime you clean the obj directory you must run dotnet restore

like image 165
TerribleDev Avatar answered Oct 23 '22 12:10

TerribleDev