Visual Studio 2017 csproj .NET CORE netstandard2.0 not building - visual-studio-2017

I just installed VS2017 and did the one way migration of my .NET core projects from the project.json format to the new csproj format. What I want is to target multiple frameworks so I can build a Framework Depedenent Deployment and a Self Contained Deployment using a smaller footprint. I followed the directions on the MS docs, but when I include netstandard1.6 or netstandard2.0 in the TargetFrameworks, I get a whole slew of Predefined type System.Object is not defined and The type of namespace System could not be found among others when I try and build the project. This worked when it was using the project.json file. My csproj is
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>1.0.0.0</VersionPrefix>
<TargetFrameworks>netcoreapp1.2;netstandard2.0</TargetFrameworks>
<AssemblyName>App</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>App</PackageId>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.2' ">1.1.1</RuntimeFrameworkVersion>-->
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard2.0' ">1.6.1</NetStandardImplicitPackageVersion>
<RuntimeIdentifiers>win10-x64;android.21;android21-arm64;osx.10.12;rhel7.4;centos.7-x64;debian8-x64;ubuntu16.10-x64;fedora.26-x64;opensuse.42.1-x64</RuntimeIdentifiers>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute
</PropertyGroup>
<ItemGroup>
<None Remove="App.csproj.vspscc" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
<PackageReference Include="Microsoft.NETCore.Runtime.CoreCLR" Version="1.1.0" />
</ItemGroup>
</Project>
My original project.json
{
"version": "1.0.0.0",
"buildOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.2": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
}
},
"netstandard2.0": {
"dependencies": {
"NETStandard.Library": {
"version": "1.6.1"
},
"System.Threading.Thread": "4.3.0",
"Microsoft.NETCore.Runtime.CoreCLR": "1.1.0"
}
}
},
"runtimes": {
"win10-x64": {}
"ubuntu.16.10-x64": {},
"centos.7-x64": {},
"debian.8-x64": {},
"fedora.24-x64": {},
"opensuse.42.1-x64": {},
"osx10.12-x64" : {}
}
}
Not sure what the problem is. Am I trying to do something unsupported? If I have just netcoreapp1.2, when I do a dotnet publish -c Release -r win10-x64 I still get a FDD output, not a standalone executable. I feel like this was way easier with the json file... What am I doing wrong?

I got the same error message when the Nuget-packages were not restored. Have you made sure the packages are restored properly, and that no errors appear if you run "dotnet restore"?

Related

Unit Test fails to run on solution based on Helix Visual Studio Templates

my project solution is based on Sitecore Helix Visual Studio Templates by Ander's Laub. Im trying to write Unit tests using XUnit, but none of the tests are running and not even failing.
For test projects, I have tried using Project based on Class Library(.NET Framework), Projects based on Sitecore Helix Visual Studio Templates by Ander's Laub.
Packages used:
XUnit(2.4.1)
XUnit.Runner.VisualStudio(2.4.3)
XUnit.Runner.Console(2.4.1)
Framework: .NET 4.8
Visual Studio 2019: v16.8.5
The output im getting:
Since Im not able to post images, here is the Text Explorer details:
Group Summary
Linde.Foundation.SitecoreExtensions.Tests
Tests in group: 1
Outcomes
1 Not Run
DemoTests.cs
public class DemoTests
{
[Fact]
public void DemoTestForPassingOnly()
{
double expected = 5;
double actual = 4;
Assert.Equal(expected, actual);
}
}
Test Run Output window:
ProjectData: Could not find project with GUID 09fe023c-998c-4a4c-a896-bc27884e7aaf
ProjectData: Could not find project with GUID 09fe023c-998c-4a4c-a896-bc27884e7aaf
---------- Starting test run ----------
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.3+1b45f5407b (64-bit Desktop .NET 4.0.30319.42000)
No test matches the given testcase filter `FullyQualifiedName=Linde.Foundation.SitecoreExtensions.Tests.DemoTests.DemoTestForPassingOnly` in C:\SourceTree\lindemh-sitecore\bin\Debug\Linde.Foundation.SitecoreExtensions.Tests.dll
========== Test run finished: 0 Tests run in 1.3 sec (0 Passed, 0 Failed, 0 Skipped) ==========
I have tried building a separate Console Application with Tests project to make sure whether this is a Visual Studio Issue, but it is running/failing/passing inside the console application, but not inside the Sitecore Project.
Do I have to configure the solution differently in order for the Tests to run successfully?
For simple unit tests using xunit I only have those references in my package :
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.4.1" targetFramework="net462" />
<package id="xunit.abstractions" version="2.0.3" targetFramework="net462" />
<package id="xunit.analyzers" version="0.10.0" targetFramework="net462" />
<package id="xunit.assert" version="2.4.1" targetFramework="net462" />
<package id="xunit.core" version="2.4.1" targetFramework="net462" />
<package id="xunit.extensibility.core" version="2.4.1" targetFramework="net462" />
<package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net462" />
<package id="xunit.runner.console" version="2.4.1" targetFramework="net462" developmentDependency="true" />
<package id="xunit.runner.visualstudio" version="2.4.1" targetFramework="net462" developmentDependency="true" />
</packages>
So I believe the XUnit.Runner.VisualStudio(2.4.3) should be 2.4.1.
Then a simple test could look like that
using aProject.Foundation.Utilities.Extensions;
using Xunit;
namespace aProject.Foundation.Utilities.Tests
{
public class ExtensionsTests
{
public class StringExtensionTests
{
[Theory]
[InlineData("some awesome string")]
[InlineData(" some awesome string ")]
public void Should_returnValidSlug_When_passingStringWithSpaces(string name)
{
Assert.Equal("some-awesome-string", name.ToSlug());
}
}
}
}

Build issues after updating to visual studio 15.8.5

Does anyone have experience with this error?
Severity Code Description Project File Line Suppression State
Error The item "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\Microsoft.Win32.Primitives.dll" in item list "ReferencePath" does not define a value for metadata "CopyLocal". In order to use this metadata, either qualify it by specifying %(ReferencePath.CopyLocal), or ensure that all items in this list define a value for this metadata. Batch_WPF
If I downgrade visual studio the issue goes away.
I've fixed this error by removing the following code in my .csproj file.
<Target Name="FixClickOnceDependencies" BeforeTargets="_DeploymentComputeClickOnceManifestInfo">
<ItemGroup>
<_noCopyRefs Include="#(ReferencePath)" Condition="'%(ReferencePath.Private)' == 'false'" />
<_noCopyRefsByFileName Include="#(_noCopyRefs->'%(FileName)')">
<OriginalItem>%(Identity)</OriginalItem>
</_noCopyRefsByFileName>
<_libByFileName Include="#(ReferenceCopyLocalPaths->'%(FileName)')">
<OriginalItem>%(Identity)</OriginalItem>
</_libByFileName>
<_overlappingRefByFileName Include="#(_noCopyRefsByFileName)" Condition="'#(_noCopyRefsByFileName)' == '#(_libByFileName)' AND '%(Identity)' != ''" />
<_overlappingLibByFileName Include="#(_libByFileName)" Condition="'#(_noCopyRefsByFileName)' == '#(_libByFileName)' AND '%(Identity)' != ''" />
<_overlappingRef Include="#(_overlappingRefByFileName->'%(OriginalItem)')" />
<_overlappingLib Include="#(_overlappingLibByFileName->'%(OriginalItem)')" />
</ItemGroup>
<ItemGroup Condition="'#(_overlappingRef)' != ''">
<ReferencePath Remove="#(_overlappingRef)" />
<ReferencePath Include="#(_overlappingLib)">
<Private>True</Private>
</ReferencePath>
</ItemGroup>
I added this code in order to fix an error with Click Once, as described here: https://github.com/dotnet/standard/issues/529

JUnit 5 Console does not find tests

I am using JUnit5 Console in my Ant build script. However it does not find any tests in my project.
I've used the following command in Terminal:
-jar lib\junit-platform-console-standalone-1.1.0-RC1.jar --class-path bin --scan-class-path
which returns:
[36m.[0m
[36m+--[0m [36mJUnit Jupiter[0m [32m[OK][0m
[36m'--[0m [36mJUnit Vintage[0m [32m[OK][0m
Test run finished after 27 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]
I get the same output for the Ant script:
<target name="test" depends="compile" description="Runs JUnit Tests">
<java jar="lib\junit-platform-console-standalone-1.1.0-RC1.jar" fork="true">
<arg value="d ."/>
<arg value="-details verbose"/>
</java>
</target>
I fixed it: The Arguments have to be lines:
<target name="test" depends="test-javac" description="Runs JUnit Tests">
<java jar="${junit.jar}" fork="true">
<arg line="--class-path bin"/>
<arg line="--scan-class-path"/>
<arg line="--reports-dir reports"/>
<!-- Available options: [ascii,unicode]-->
<arg line="details-theme unicode"/>
<!-- Available options: [none,flat,tree,verbose]-->
<arg line="--details tree"/>
</java>
</target>
You need to specify where the launcher can find your compiled test classes. See https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher for details.
How are your test classes named? Are they stored by "javac" directly under "bin/"?
Maybe the answer and comments posted here Unable to run tests with JUnit5 Console Launcher are helpful.

Is there a way to get build status as a property?

I have a ugly Teamcity build configuration using MSBuild. It executes custom application (test runner), which is using custom messaging to report test results to teamcity.
##teamcity[testStarted name='test1']
##teamcity[testFailed name='test1' message='failure message' details='message and stack trace']
Which show in teamcity in build overview and tests tab.
Teamcity recognizes failed tests and if any test fails, it marks the build as failed:
http://i.stack.imgur.com/Qz9UT.png
Later in the MSBuild target I would like to label cvs based on the test results.
Is there a way to get the build status (if it is failed, hanging, warning) as a property? something like %build.status%? The format does not matter - if its a string or number.
PS: I know that best solution to my problem would be to modify the application to return non-zero exit code if test fail.
TeamCty does not seem to expose this directly, but the status can be acquired using the REST api. Here is an example using curl; but you could also uwe PowserShell's Invoke-RestMethod for instance.
Here's the msbuild script that casues test failure I used for testing:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Test">
<Message Importance="high" Text="##teamcity[testStarted name='test1']" />
<Message Importance="high" Text="##teamcity[testFailed name='test1' message='failure message' details='message and stack trace']" />
</Target>
</Project>
Then the script that gets the current build's status, dumps it to a file, reads the file into an msbuild item and then uses regex to get the status out of it. You just have it to supply the tc_user and tc_password properties (or allow guest access) and change the url to match your server.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="GetBuildStatus">
<Target Name="RunCurl">
<PropertyGroup>
<MyTempFile>curl_out</MyTempFile>
</PropertyGroup>
<Exec Command="curl http://localhost/httpAuth/app/rest/builds/id:$(teamcity_build_id) -basic -u $(tc_user):$(tc_password) > $(MyTempFile)"/>
<ReadLinesFromFile File="$(MyTempFile)">
<Output TaskParameter="Lines" ItemName="CurlOutput"/>
</ReadLinesFromFile>
<Delete Files="$(MyTempFile)"/>
</Target>
<Target Name="GetBuildStatus" DependsOnTargets="RunCurl">
<PropertyGroup>
<CurlOutputFull>#(CurlOutput)</CurlOutputFull>
<BuildStatus>$([System.Text.RegularExpressions.Regex]::Match($(CurlOutputFull), `status="(\w*)"`).Groups[ 1 ].Value)</BuildStatus>
</PropertyGroup>
<Message Text="BuildStatus = $(BuildStatus)"/>
</Target>
</Project>
This prints:
BuildStatus = FAILURE

VS2010 custom build tool for generating .h file

I'm trying to integrate a custom build tool in VS2010 that generates a .h-file from a source file. I've created a .xml, .targets and .props for the step. The XML is mostly copy-pasted from the MASM-file and ends with:
<ItemType Name="FOO" DisplayName="Foo compiler" />
<FileExtension Name="*.foo" ContentType="FOO" />
<ContentType Name="FOO" DisplayName="Foo compiler" ItemType="FOO" />
This maps all my .foo files to the Foo compiler that's defined in the .props:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml" />
<AvailableItemName Include="FOO">
<Targets>FooCompile</Targets>
</AvailableItemName>
</ItemGroup>
<UsingTask TaskName="FOO" TaskFactory="XamlTaskFactory" AssemblyName="Microsoft.Build.Tasks.v4.0">
<Task>$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml</Task>
</UsingTask>
<Target Name="FooCompile" BeforeTargets="$(FOOBeforeTargets)" AfterTargets="$(FOOAfterTargets)" Condition="'#(FOO)' != ''" Outputs="%(FOO.Outputs)" Inputs="%(FOO.Identity);%(FOO.AdditionalDependencies);$(MSBuildProjectFile)" DependsOnTargets="_SelectedFiles">
<Message Importance="High" Text="#(FOO)" />
<FOO Condition="'#(FOO)' != '' and '%(FOO.ExcludedFromBuild)' != 'true'"
CommandLineTemplate="%(FOO.CommandLineTemplate)"
OutputFileName="%(FOO.OutputFileName)"
Inputs="%(FOO.Identity)" />
</Target>
</Project>
When I compile my project it successfully identifies and compiles my foo files:
1>FooCompile:
1> apa.foo
1>FooCompile:
1> banan.foo
1>ClCompile:
1> test.cpp
1> main.cpp
My question is why does it print "FooCompile:" once for each file while the ClCompile doesn't? Is there any way to change this?
If I change a cpp file and build, I'll also get this output once for each file, which I want to avoid:
1>FooCompile:
1>Skipping target "FooCompile" because all output files are up-to-date with respect to the input files.
1>FooCompile:
1>Skipping target "FooCompile" because all output files are up-to-date with respect to the input files.
The FooCompile target is using "target batching" which causes the target to iterate once for each item in the array specified for the Outputs attribute, %(Foo). The ClCompile target on the other hand operates using the entire item array #(ClCompile).
You can alter the verbosity of the logger to avoid the messages, specify /v:minimal, but of course you may be filtering out other information as well.