I have a requirement to work with Jenkins for Continues integration, in my code I have written code like
throw new ArgumentNullException($"The {nameof(Id)} cannot be null");
If I build the application it is building successfully but if I build this same application using MsBuild(or) Jenkins,
I am getting error like
Web\WebSharedHelper.cs "C:\WINDOWS\TEMP\.NETFramework,Version=v4.5.2.AssemblyAttributes.cs"
Security\ApiUserToken.cs(46,32): error CS1056: Unexpected character '$' [C:\Program Files (x86)\Jenkins\workspace\OssiaCICD\common\trunk\Cota.Common.Core\Cota.Common.Core.csproj]
Security\ApiUserToken.cs(58,32): error CS1056: Unexpected character '$' [C:\Program Files (x86)\Jenkins\workspace\OssiaCICD\common\trunk\Cota.Common.Core\Cota.Common.Core.csproj]
Security\ApiUserToken.cs(62,26): error CS1056: Unexpected character '$' [C:\Program Files (x86)\Jenkins\workspace\OssiaCICD\common\trunk\Cota.Common.Core\Cota.Common.Core.csproj]
Done Building Project "C:\Program Files (x86)\Jenkins\workspace\OssiaCICD\common\trunk\Cota.Common.Core\Cota.Common.Core.csproj" (default targets) -- FAILED.
I am using v4.0.30319 FrameWork for MSBuild.
I fixed the problem by using C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe instead of C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe on jenkins.
The $ string interpolation symbol is only available in C# 6+. Make sure that you are compiling with C#6. C#6 is supported in MSBuild 14.0+.
If your Visual Studio version is older than 2015 then by default the IDE does not provide C#6 which you need to compile it.
Use Visual Studio 2015 or newer. It should resolve problem.
This problem can be resolved in a couple of ways. Please check my answer here
for the first option:
1st https://stackoverflow.com/a/42931980/819153
2nd option - Try to install the visual studio on the tfs where you run the continuous integration, that will save you a lot of headaches
As suggested by a gentleman here, I used C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe instead of C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe over the build agent.
And it helped me.
I have MSBuild Version 14.0.25420.1 in the build agent.
In my case, worked below..
Removed langversion nodes and added netstandard reference to csproj for msbuild to work with Jenkins or msbuild command.
commented below lines in .csproj file.
<!-- <LangVersion>8.0</LangVersion>-->
And added <Reference Include="netstandard" /> for more-info
Related
I have been trying to build a .NET project with visual studio 2017 Community on my local.
The build works fine when done using Publish option but throws below error when trying using msbuild
C:\Users\ajay3\source\repos\Triyo.API\TriyoCore.API>msbuild
Microsoft (R) Build Engine version 4.8.4084.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2021-06-28 3:55:47 PM.
Project "C:\Users\ajay3\source\repos\Triyo.API\TriyoCore.API\TriyoCore.API.csproj" on node 1 (default targets).
C:\Users\ajay3\source\repos\Triyo.API\TriyoCore.API\TriyoCore.API.csproj(281,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualSt
udio\**v11.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.
Done Building Project "C:\Users\ajay3\source\repos\Triyo.API\TriyoCore.API\TriyoCore.API.csproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\ajay3\source\repos\Triyo.API\TriyoCore.API\TriyoCore.API.csproj" (default target) (1) ->
C:\Users\ajay3\source\repos\Triyo.API\TriyoCore.API\TriyoCore.API.csproj(281,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Visual
Studio\**v11.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.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.08
I have gone through various similar articles on Stackoverflow and various other sites but none of them help.
Where it is pulling v11.0 from? I don't have that value in my csproj file.
Are you using correct version of MSBuild?
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\MSBuild.exe
The path to MSBuild could be different depending on your pc
If Yes check the following example
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe C:\Users\ajay3\source\repos\Triyo.API\TriyoCore.API\TriyoCore.API.csproj /t:Clean
For more information run the following command:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /?
You can also use this link
I cleaned up my system and reinstalled msbuild and it works fine now.
I am using VS Community Studio 2019 to build a new web page with ASP.NET. Upon creating new RESTful API templates, I receive this kind of error:
Project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\v16.0\TypeScript\Microsoft.TypeScript.targets" was not imported by "C:\Program Files\dotnet\sdk\3.1.200\Sdks\Microsoft.NET.Sdk.Web.ProjectSystem\targets\Microsoft.NET.Sdk.Web.ProjectSystem.targets" at (14,3), due to the file being invalid
It is also an issue for Microsoft.Typescript.Default.props and Microsoft.TypeScript.DotNetCore.targets, leading to an error (I guess) :Root element is missing.
Is there any solution for it?
For the same error in my case this worked :
1 - Go to NuGet packages manager
2 - Install this package : Microsoft.TypesCript.MSBuild
Regards
After reinstalling the TypeScript SDK, the error became an warning: "This is most likely a build authoring error. This subsequent import will be ignored."
The build for my solution, which contains multiple projects, suddenly appears to be broken and the cause of the issue isn't clear. All of the projects in the solution target the same framework (4.5.1), however, some of the projects' dependencies might be targeting an earlier version of the framework. As of last week, we were able to successfully build solutions that fall under this scenario. Starting last Thursday, the builds appear to be broken without any changes to the build server or the solution.
To illustrate and remove some of the complexities with our production setup, I created a sample solution which mimics the behavior.
Project structure:
CBI Solution
CBI website
CBI Implementation Library
CBI Core library, defining the interfaces
Target Framework Version for the website and class libraries is 4.5.1
Replication Steps
Solution 1
Github repo: https://github.com/NikitaGolovko/Solution1.git
Build, using MSBuild 14. My command is:
msbuild.exe "%SOLUTION1PATH%\CBILite.sln" /p:platform="Any CPU" /p:configuration="Release" /v:d
Output
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_61806 -p cbi\ -u -f PrecompiledWeb\lo
calhost_61806\
Microsoft (R) ASP.NET Compilation Tool version 4.7.2046.0
Utility to precompile an ASP.NET application
Copyright (C) Microsoft Corporation. All rights reserved.
Done executing task "AspNetCompiler".
Task "Message" skipped, due to false condition; (!((false) or ('$(AspNetConfiguration)' == 'Debug') or ('$(AspNetConfig
uration)' == 'Release'))) was evaluated as (!((false) or ('Release' == 'Debug') or ('Release' == 'Release'))).
Done building target "Build" in project "cbi.metaproj".
Done Building Project "D:\Work\DotNet\Nikita\Solution1\cbi.metaproj" (default targets).
Done executing task "MSBuild".
Done building target "Build" in project "CBILite.sln".
Done Building Project "D:\Work\DotNet\Nikita\Solution1\CBILite.sln" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:03.10
Full output is located here: https://github.com/NikitaGolovko/Solution1/blob/master/MSBuild_Output.txt
Solution 2
Github Repo: https://github.com/NikitaGolovko/Solution2.git
The solution is nearly identical to the Solution1, with the only exception being a dependency for Unity in CBI Implementation library. To simplify the process and eliminate the nuget restore step, I have included nuget packages with the solution.
Build, using MSBuild 14. My command is:
msbuild.exe "%SOLUTION2PATH%\CBILite.sln" /p:platform="Any CPU" /p:configuration="Release" /v:d
Output
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_61806 -p cbi\ -u -f PrecompiledWeb\lo
calhost_61806\
Microsoft (R) ASP.NET Compilation Tool version 4.7.2046.0
Utility to precompile an ASP.NET application
Copyright (C) Microsoft Corporation. All rights reserved.
D:\Work\DotNet\Nikita\Solution2\cbi\Index.aspx.vb(5): error BC30002: Type 'CBILite.Calculator' is not defined. [D:\Work
\DotNet\Nikita\Solution2\cbi.metaproj]
The command exited with code 1.
Done executing task "AspNetCompiler" -- FAILED.
Done building target "Build" in project "cbi.metaproj" -- FAILED.
Done Building Project "D:\Work\DotNet\Nikita\Solution2\cbi.metaproj" (default targets) -- FAILED.
Done executing task "MSBuild" -- FAILED.
Done building target "Build" in project "CBILite.sln" -- FAILED.
Done Building Project "D:\Work\DotNet\Nikita\Solution2\CBILite.sln" (default targets) -- FAILED.
Build FAILED.
Full output is located here: https://github.com/NikitaGolovko/Solution2/blob/master/MSBuild_Output.txt
Observations
Bin folder
When looking in the bin folder of the website, I notice that CBILite.dll is missing after the build for Solution2, but present in Solution1.
TargetFrameworkVersion
Passing TargetFrameworkVersion in the MSBuild arguments does not appear to influence the build. I have attempted to pass 4.5, 4.5.1 to no avail. HOWEVER passing 3.5 results in the successful build. This is extremely strange.
Metaproj
When comparing Metaproj files generated for both solutions, the only observable and seemingly important difference is the lack of the TargetFrameworkVersion element. Solution1 (without dependencies), contains v.4.0 element. Solution2 (with the dependency) does not.
I didn't include metaproj files in the repo but can share them if needed.
Visual Studio
Building the solution in Visual Studio works just fine.
Additional thoughts
The issue manifested itself rather suddenly and seems to be affecting most of our solutions that have mixed projects (C#/VB + website). Web Projects continue to function normally.
I've attempted to use MSBuild 15, but it resulted in the same behavior.
There are a few workarounds
Retaining the metaproj file with the solution and modifying it manually by adding v4.5.1 element.
Adding an additional build step to manually copy CBILib.dll into the website project (via the batch file or other means).
Adding a refresh file for the website pointing to CBILib/bin/Release folder
While all of these solutions might work, they're certainly hacks and will present problems in the future.
I'm hoping someone else has a better suggestion on how to handle this.
Make sure you have installed the following NuGet packages:
Microsoft.NET.Test.Sdk
MSTest.TestAdapter
MSTest.TestFramework
Microsoft.NETCore.App (if you use .NET Core)
SonarQube is giving me below error when i integrate the xamarin app with jenkins on windows sever
SonarQube Scanner for MSBuild 3.0
Default properties file was found at C:\SonarQube\bin\SonarQube.Analysis.xml
Loading analysis properties from C:\SonarQube\bin\SonarQube.Analysis.xml
Post-processing started.
13:49:43.952 SonarQube analysis could not be completed because the analysis configuration file could not be found: C:\Users\Administrator\.jenkins\workspace\Xamarin-ProjectTemplate\.sonarqube\conf\SonarQubeAnalysisConfig.xml.
13:49:43.952 Post-processing failed. Exit code: 1
I have followed the below guide https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild
SonarQube.Scanner.MSBuild.exe begin /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"Project Name" /v:"1.0"
MSBuild.exe /t:Rebuild
SonarQube.Scanner.MSBuild.exe end
Please help me to resolve this issue
The errors reported at the end of a SonarQube report are sometimes less helpful than the errors when you begin.
Eg when I got this error, scrolling to the top of the log showed that I wasn't correctly setting the sonar.projectKey value, but this message the OP shared is still what showed up at the end.
I had the same problem. You need find correct MSBuild.exe.
I have several in c:\Windows\Microsoft.NET\Framework64\... and also in c:\Program Files (x86)
For my project in Visual Studio 2017 with .NETFramework,Version=v4.6.1 the correct MSBuild.exe is:
"c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe" /t:Rebuild
For the Enterpsie version is should be:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild" /t:Rebuild
I got the same error and was able to fix it by excluding "/t:Rebuild" from second step. Also used the VS2017 MSBuild.exe
These are the 3 commands I ran in Windows Command Prompt (CMD):
1>> SonarScanner.MSBuild.exe begin /k:"MyProjectName"
2>> "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe" "MySolution.sln"
3>> SonarScanner.MSBuild.exe end
Update I confront this error also , my solution was easy I just build the project in the visual studio then its succeeded.
I had this problem because I used a bad project key (it had a }) inside. I removed the }and the problem was gone.
I ran into compilation problems with my MSVS 10 after installing MSVS 11Beta. Now, when I compile my C# Projects in MSVS 10 (Projects created in MSVS 10; Target framework: 3.5), I get errors MSB4216, MSB4028 with following text in output window:
1>Task "GenerateResource" skipped, due to false condition; ('%(EmbeddedResource.Type)' == 'Resx' and '%(EmbeddedResource.GenerateResource)' != 'false' and '$(GenerateResourceMSBuildRuntime)' != 'CLR2') was evaluated as ('Resx' == 'Resx' and '' != 'false' and 'CLR2' != 'CLR2').
1>Task "GenerateResource"
1> Launching task "GenerateResource" from assembly "Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" in an external task host with a runtime of "CLR2" and a process architecture of "x86".
1>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(2199,5): error MSB4216: Could not run the "GenerateResource" task because we could not create or connect to a task host with runtime "CLR2" and architecture "x86". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NetFX 4.0 Tools\MSBuildTaskHost.exe" exists.
1>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(2217,7): error MSB4028: The "GenerateResource" task's outputs could not be retrieved from the "FilesWritten" parameter. Object does not match target type.
1>Done executing task "GenerateResource" -- FAILED.
How can I fix these errors?
EDIT:
Mentioned file "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NetFX 4.0 Tools\MSBuildTaskHost.exe" exists.
C++ projects are compling without problems.
Reinstalling VS10 doesn't solve the problem.
This is GenerateResource task, that must compile resx-file, but generates an exception:
<!-- But we can't use those parameters if we're targeting 3.5, since we're using the 3.5 task -->
<GenerateResource
Sources="#(EmbeddedResource)"
UseSourcePath="$(UseSourcePath)"
References="#(ReferencePath)"
AdditionalInputs="$(MSBuildAllProjects)"
NeverLockTypeAssemblies="$(GenerateResourceNeverLockTypeAssemblies)"
StateFile="$(IntermediateOutputPath)$(MSBuildProjectFile).GenerateResource.Cache"
StronglyTypedClassName="%(EmbeddedResource.StronglyTypedClassName)"
StronglyTypedFileName="%(EmbeddedResource.StronglyTypedFileName)"
StronglyTypedLanguage="%(EmbeddedResource.StronglyTypedLanguage)"
StronglyTypedNamespace="%(EmbeddedResource.StronglyTypedNamespace)"
StronglyTypedManifestPrefix="%(EmbeddedResource.StronglyTypedManifestPrefix)"
PublicClass="%(EmbeddedResource.PublicClass)"
OutputResources="#(EmbeddedResource->'$(IntermediateOutputPath)%(ManifestResourceName).resources')"
MSBuildRuntime="$(GenerateResourceMSBuildRuntime)"
MSBuildArchitecture="$(GenerateResourceMSBuildArchitecture)"
Condition="'%(EmbeddedResource.Type)' == 'Resx' and '%(EmbeddedResource.GenerateResource)' != 'false' and '$(GenerateResourceMSBuildRuntime)' == 'CLR2'">
I tried to debug MSBuild script (.csproj). Just before the fatal GenerateResource task I checked all the properties and items. There was nothing about "8.0A" but only about "7.0A"
There is an ugly way to fix the problem: renaming folder "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A". I hate to accept this answer.
How long is your username?
It seems that there is a bug when the username is 20 characters long. If your username is 19 characters or less it works fine.
I have opened an issue on connect.
Edit:
Have you tried setting the environment variable DisableOutOfProcTaskHost to true as suggested in the connect issue, that worked for me.
A similar questin was asked on the MSDN forums. Did you reboot after installing VS11?
http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/7d955d96-ff73-47d3-8830-85ea321eb4ab
This issue occurred for me on my TFS 2010 build server after installing VS2010 and then installing .NET Framework 4.5. This allowed me to build .NET 4.5 projects but any VS2008 project targeting CLR2 (.NET 2.0 -3.5) I attempted to build would return the error. None of the suggestions on the handful of sites talking about this issue worked.
Rebooting - Did not fix the issue
Setting DisableOutOfProcTaskHost = true in an environment variable and also within the project file - Did not fix the issue
Username of my build account was already less than 20 characters
Renaming windows SDK folder - N/A since I did not have VS2012 and the 8.0A SDK installed... just .NET framework 4.5.
In any case, to fix this I uninstalled .NET 4.5, repaired VS2010, and then rebooted the build server. Now I am able to build VS2008 and VS2010 projects with no issues.
Luckily I no longer need to build .NET 4.5 projects as that team decided to go back to .NET 4.0.
Another possible fix is to change the target framework of your projects to .Net 4.0. It's not always a solution, but it certainly is a possibility if all else fails.
Worked for me: Removing the bin and obj folder for problematic folders and restarting the solution
In my case, I received that error message when trying to build a solution on a 32-bit Windows 7 machine. The way to resolve the error for me was to right-click on the project, choose properties, then go to the Build tab. In here I changed the "Platform target" from "Any CPU" to "x86". HTH
Setting Setting DisableOutOfProcTaskHost = true in an environment variable worked for me.