GetReferenceNearestTargetFramwork task failed unexpectedly. Invalid framework V4.0 - visual-studio-2010

I'm am trying to build a VS2010 project in VS2019. I also get this error message in VS2017 as well.
The project will not build because it seems to not recognize MSbuild 4.0 as being valid.
This is the error:
The "GetReferenceNearestTargetFrameworkTask" task failed unexpectedly.
System.ArgumentException: Invalid framework version 'V4.0'.
at NuGet.Frameworks.NuGetFramework.ParseFrameworkName(String frameworkName, IFrameworkNameProvider mappings)
at NuGet.Frameworks.NuGetFramework.Parse(String folderName, IFrameworkNameProvider mappings)
at
NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask.TryParseFramework(String framework, String errorMessage, MSBuildLogger logger, NuGetFramework& nugetFramework)
Here is the task that fails:
<GetReferenceNearestTargetFrameworkTask AnnotatedProjectReferences="#(_ProjectReferenceTargetFrameworkPossibilities)"
CurrentProjectTargetFramework="$(ReferringTargetFrameworkForProjectReferences)"
CurrentProjectName="$(MSBuildProjectName)"
FallbackTargetFrameworks="$(AssetTargetFallback)"
Condition="'#(_ProjectReferenceTargetFrameworkPossibilities->Count())' != '0' and '$(ReferringTargetFrameworkForProjectReferences)' != ''">
<Output ItemName="AnnotatedProjects" TaskParameter="AssignedProjects" />
</GetReferenceNearestTargetFrameworkTask>

The GetReferenceNearestTargetFrameworkTask will be called during build process.
And see Condition="'#(_ProjectReferenceTargetFrameworkPossibilities->Count())' != '0' and '$(ReferringTargetFrameworkForProjectReferences)' != ''", this task will run when current project have project reference to other projects.
If this task executes, the value of <TargetFrameworkVersion> will be passed to GetReferenceNearestTargetFrameworkTask class from NuGet.Build.Tasks.dll. And it can't recognize the V4.0, in VS2019, the framewrok version starts with v instead of V.
So the workaround is to open the xx.csproj file, and change the <TargetFrameworkVersion>V4.0</TargetFrameworkVersion> to <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> and run a rebuild. Hope it helps:)

Related

Error while running MSBuild.SonarQube.Runner against C# project

I’m trying to use MSBuild SonarQube scanner for my C# project. RootFolder has a .sln file, and each project (.csproj) is created in a separate folder inside the root folder. I've the project property file in RootFolder.
SonarQube server (LTS version 6.7.5) is up fine.
My Current env details:
Visual Studio 2010
.Net Framework 4.5.2
MSBuild version 4
sonarScanner for MSBuild 4.3.1.1372
Sonar Csharp Plugin version : 7.3.2.6129
When I’m trying to run below ‘begin’ command from project root directory, I see this error:
M:\myProjectCsharp>MSBuild.SonarQube.Runner.exe begin /k:”myProjectCsharp”/n: “myProjectCsharp”/v:”1.0”
Unhandled Exception: System.MissingMethodException: Method not found: '!!0[] System.Array.Empty()'.
at SonarScanner.MSBuild.Program.Execute(String[] args, Boolean showDeprecatedWarning)
at MSBuild.SonarQube.Runner.Program.Main(String[] args)
I guess it has something to do with compatibility of .Net Framework or MSBuild version ?
Also, what's the role of visual studio here, I already got.sln, .csproject and their corresponding .cs files in respective project directory under RootFolder 'myProjectCsharp'
(I don’t see any error if I simply run the sonar-scanner-msbuild-4.3.1.1372-net46\sonar-scanner-3.2.0.1227\bin\sonar-scanner but this doesn’t seems to update anything on dashboard (Just show 0 Bugs,Vulnerabilities & code smells) )
Any clue please ?
Thanks.

Simd library compilation fails

I'm trying to build the Simd library on Visual Studio 2017.
https://github.com/ermig1979/Simd
I opened the project from /prj/vs2017w.
I just modified the configuration type from dynamic to static lib.
And I uncommented the #define SIMD_STATIC from the file SimdConfig.h
After the compilation I get this error :
error MSB3073: The command "C:\Users\fullPath\Simd\prj\vs2017w\..\cmd\GetVersion.cmd
error MSB3073: :VCEnd" exited with code 9009
The problem is here when I click on the error :
<Target Name="PreBuildEvent" Condition="'$(PreBuildEventUseInBuild)'!='false'">
<Message Text="Description: %(PreBuildEvent.Message)" Condition="'%(PreBuildEvent.Message)' != '' and '%(PreBuildEvent.Command)' != ''"/>
<Exec Command="%(PreBuildEvent.Command)$(_BuildSuffix)" Condition="'%(PreBuildEvent.Command)' != ''"/>
</Target>
I tried to reload the project etc but nothing works.
Also tried with VS2015 from /prj/vs2015 but same issue.
I just to want to have the Simd.lib in every configuration (x64 / x86 debug & release) for my project.
Any solution ? Thanks for help
There was a bug in Visual Studio project file for Simd Library:
<Command>$(ProjectDir)\..\cmd\GetVersion.cmd</Command>
If project directory has a space then there is an error during calling of pre build script. The solution of this error is very simple - just add quotes to the project directory:
<Command>"$(ProjectDir)"\..\cmd\GetVersion.cmd</Command>
I resolved the issue.. By looking to the output I noticed that the script stops when there is a space in the path ... So he does not have access to the .cmd file.
Thanks

SonarQube Scanner for MSBuild on macOS using mono

I'm trying to use SonarQube Scanner for MSBuild on a Xamarin project on macOS using mono. As MSBuild 15.0 is now shipped with Xamarin, I figured this could actually work.
I can successfully run the scanner's "begin" using mono like so:
mono sonar-scanner-msbuild-2/SonarQube.Scanner.MSBuild.exe begin /k:"KEY"
The command creates the following files:
.sonarqube/conf/SonarQubeAnalysisConfig.xml
.sonarqube/conf/SonarQubeRoslyn-cs.ruleset
.sonarqube/conf/cs/SonarLint.xml
Before running MSBuild, I've added the following import to the csproj files of my solution:
<Import Project="/Users/someuser/.local/share/Microsoft/MSBuild/14.0/Microsoft.Common.targets/ImportBefore/SonarQube.Integration.ImportBefore.targets" />
I'm running MSBuild using:
msbuild /t:Rebuild
Now the build starts correctly but eventually terminates with two errors:
"/Users/someuser/Project/Project.sln" (Rebuild target) (1) ->
"/Users/someuser/Project/Project.UI.iOS/Project.UI.iOS.csproj" (Rebuild target) (2) ->
"/Users/someuser/Project/Project.Core/Project.Core.csproj" (default target) (3:3) ->
(CoreCompile target) ->
CSC : error CS2001: Source file `/additionalfile:/Users/someuser/Project/.sonarqube/conf/cs/SonarLint.xml' could not be found [/Users/someuser/Project/Project.Core/Project.Core.csproj]
CSC : error CS2001: Source file `/additionalfile:/Users/someuser/Project/.sonarqube/conf/Project.Core_AnyCPU_Debug_1267/ProjectOutFolderPath.txt' could not be found [/Users/someuser/Project/Project.Core/Project.Core.csproj]
Both files do exist in the filesystem, the first file was created in the scanner's begin invocation and the second file was created during the MSBuild execution.
Why would MSBuild not be able to find / access these two files? Is there anything that can be done about it?
After checking with the folks taking care of MSBuild, the solution has been provided in this Github issue thread:
To quote radical's comment from the Github issue:
You could try building with csc by passing /p:CscToolExe=csc.exe /p:CscToolPath=/Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/msbuild/15.0/bin/Roslyn/ to msbuild
Unfortunately, even though MSBuild works with the above adjustments, SonarQube fails afterwards. I will follow up with the SonarQube people to see whether this can be worked around.

MSBuild task to Build other solution projects fails in VS but works with MSBuild.exe command line

I have a custom MSBuild task which among other things adds embedded resources to other projects in the solution. After adding the resources I'd like to then build those projects, but found I can't get this working within Visual Studio.
To test, I stripped out the custom task entirely and redefined a simple AfterBuild target in the web project of a Silverlight solution. The target uses the MSBuild task to build the Silverlight application project in the solution, and looks like this:
<Target Name="AfterBuild">
<PropertyGroup>
<LinkedProject>..\SilverlightApplication1\SilverlightApplication1.csproj</LinkedProject>
</PropertyGroup>
<MSBuild Condition="'$(LinkedProject)' != '' "
Projects="$(LinkedProject)"
Targets="Build"
Properties="CustomFlag=true" >
</MSBuild>
</Target>
The odd thing is that this works perfectly when using MSBuild from the command line, yet does not work in Visual Studio when building the web project. I thought this might be some sort of Silverlight problem, and had the task build a .NET class library project instead, but the result was the same - it worked from the command line but not within VS. In VS there's no actual error - it's just that the Csc task does not compile the assembly and generates no output.
What do I need to do to get this working within Visual Studio?
Pass the 'UseHostCompilerIfAvailable=false' property to the MSBuild task.
It looks like Visual Studio breaks badly if csc is invoked from a MSBuild task as it reuses the initial project build settings for its in-process host compiler. In my case, I was building the same project twice - default build was using target framework v3.5, with a AfterBuild MSBuild task specifying v4.0. I ended up with the same issue - csc appeared to run but produced no output. I think what was happening was that with the UseHostCompilerIfAvailable property set to true, csc was calling the hosted compiler which reused my initial project settings, so even though the command line showed csc "building" my v4.0 assembly, the host compiler was simply overwriting the v3.5 one I had just built!
Change Visual Studio verbosity to detailed and check build log. I think that CoreBuild is not executed if your files have not changed, so you could try to use AfterCompile instead of AfterBuild.

using MSBuild with VS2010-generated vcxproj file as target -- error MSB4066 ("attribute Label in element is unrecognized")

Using VS2010, I created a Win32 C++ console application called "TfsBuildTestTarget". This is just the default console application created by the wizard. I made no code or project changes, and it builds ok in VS2010 as expected.
Then I created an MSBUILD project file as follows:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<MSBuild Projects="TfsBuildTestTarget.sln" Targets="TfsBuildTestTarget" Properties="Configuration=Release;Platform=Win32"/>
</Target>
</Project>
When I run MSBUILD on this project file, I get the following error:
"c:\dev\TfsBuildTestTarget\testBuild.proj"
(default target) (1 ) ->
"c:\dev\TfsBuildTestTarget\TfsBuildTestTarget.sln"
(TfsBuildTe stTarget target) (2) ->
(TfsBuildTestTarget target) ->
c:\dev\TfsBuildTestTarget\TfsBuildTestTarget\TfsBuildTestTarget.vcxproj(3,14):
error MSB4066: The attribute "Label" in element is unrecognized.
The referenced line, in the (VS-generated) vcxproj file looks like this:
<ItemGroup Label="ProjectConfigurations">
The reference for the MSBuild item element does not include a Label attribute.
What is going on here? Why is VS2010 generating project files that do not appear to be compatible with MSBuild? Is there a way for me to build this solution as part of an MSBuild project without manually tweaking the XML?
Make sure you are using the .NET 4.0 version of MSBuild.
If you use the .NET 3.5 version of MSBuild against a VS2010 solution that includes a vcxproj file you will get this error.
I made a c++ console application like you specified and ran it using both .NET 3.5 and .NET 4.0 MSBuild versions. I got the error using 3.5 and it worked using 4.0.
The Label attribute is new in .NET 4.0. It can be added to ItemGroup, PropertyGroup, Target, and other elements. The label attribute is not mentioned in the online help for msbuild but is defined int he msbuild 4.0 schema files.
I was using the "Open Visual Studio Command Prompt (2008)" entry of Start Menu to build, and it gave me the same error, but when I switched to "Open Visual Studio Command Prompt (2010)", I had the problem miracolously solved.

Resources