Error NETSDK1004: Assets file 'project.assets.json' not found - c#

I am trying to publish my .NET 5 application, when publishing with Target runtime = Portable publish succeeds, when changing target runtime to win-x64 for example the publish fails.
Before failing i get this error in output which is probably related.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(131,5): Error : Invalid framework identifier ''.
I have noticed that the 'project.assets.json' is generated in 'obj\project.assets.json' dir but it looks like the build process actually expect it to be in 'obj\publish\win-x64\project.assets.json' and its not present there. Manually copying the file makes everything work but such approach would be very tedious.
Is there any project configuration I need to look into ?
Thanks.

Looks like the problem was caused by some dependent project libraries having AppendTargetFrameworkToOutputPath set to false.

Related

External executable not starting with error "The target process exited without raising a CoreCLR started event"

I created a class library project and configured the properties section debug to start an exe (the.exe) located in the output directory of the build (as shown in the image).
It worked as long as we had a pre-build event copying the exe and all related files from one directory in the output directory of the build. Unfortunatly this is inconvinient and we do not have track which version of the exe is used.
So I created a versioned nuget package to place all the files in the output directory. I confirmed all the required files (I know of) are in the output directory. And since I created the nuget package manually with the CLI I can confirm they are exactly the same files.
But when I try to start the application from Visual Studio 2019 now I get the following error in the debug output:
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program '[16616] the.exe' has exited with code -2147450749 (0x80008083).
Actually both (the.exe and the class library) are .NET 5.
Comparing the changes of the two setups via Git changes does not hold any clues beside adding the nuget and removing the pre-build events.
So any clue what could be the difference/problem and how to get the executable running? May I missed something?
Well, better check twice when you are stating "I confirmed all the required files (I know of) are in the output directory."
The problem was that not all files made it into the output directory.
In my case only the the.exe and the.dll were placed into the output directory. Once I checked again and ensured that also the.runtimeconfig.json (which was missing) were added it was running again and the exception were gone. Though I am not sure if there is a better way than distributing the.runtimeconfig.json.
update visual studio using Visual Studio installer worked for me. This link! helped for me.

TeamCity with SonarQube for Code Analysis build fails

Very common problem for many users, that SonarQube Code Analysis fails with an error:
[10:06:05]No ProjectInfo.xml files were found. Possible causes:
[10:06:05]1. The project has not been built - the end step was called right
after the begin step, without a build step in between
[10:06:05]2. An unsupported version of MSBuild has been used to build the
project. Currently MSBuild 12.0 upwards are supported
[10:06:05]3. The build step has been launched from a different working folder
[10:06:05]Post-processing failed. Exit code: 1
[10:06:05]Process exited with code 1
A lot of references say that fix is to use full path for MSBuild.exe, but yes, I use full path, but also I use MSBuild 15.0 version with newest C# version, older MSBuild just fails for new C# features in code.
However I can't get rid of this error and I have no idea what can be done about it, so maybe any of you guys have already met this problem and could help me?
EDITED
I am pretty sure that none of these steps should be the reason for the fail, the second one only the closest one, because my build steps are
Team City build steps look like the following.
Step XX:
cd %projectDirectory%
"C:\sonarqube-5.3\bin\MSBuild.SonarQube.Runner\MSBuild.SonarQube.Runner.exe" begin ... params
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" "MyProject.sln" /t:Clean;Rebuild
Step XY:
...
Step XZ: (the last)
cd %projectDirectory%
"C:\sonarqube-5.3\bin\MSBuild.SonarQube.Runner\MSBuild.SonarQube.Runner.exe" end
For me it looks very simple and easy to understand, but still I got that error and I have no idea why, the error is thrown in the last step (XZ).
You need to upgrade to a newer version of the Scanner for MSBuild. I'd suggest upgrading to the newest available version (v4.2 at the time of writing).
The scanner copies a targets file under the following location for each supported version of MBuild: %localappdata%\Microsoft\MSBuild[MSBuild version]\Microsoft.Common.targets\ImportBefore.
From the look of the log output you are using an version of the Scanner for MSBuild that pre-dates the release of MSBuild 15, so the file won't be copied to the MSBuild15-specific location. This will lead to the "no ProjectInfo.xml files were found" state.
It would be better if the warning message in the scanner log explicitly listed the range of MSBuild versions that were supported e.g. "This version of the Scanner supports MSBuild v12.0 to v14.0". I've created issue #502 to track this.

Is it possible to run code analysis of .NetCore1.1 projects with SonarQube?

I've been trying to run code analysis of several .Net Core 1.1 projects, but have failed to get any results.
While using VS2015 and the project.json format I successfully sent the command:
../Sonar/tools/sonar-scanner-2.8/bin/sonar-scanner
and the sonar server shows each of the files in project(s) and test projects(s), but no analysis has actually been carried out:
Lines of code = 0
Vulnerabilities = 0
code smells = 0
Having migrated the projects to VS2017 and the csproj format, I can't even get the scan to run.
Running in the main project folder:
SonarQube.Scanner.MSBuild.exe begin /k:"Car.Enquiry-Presenter" /n:"Car.Enquiry-Presenter" /v:"1.0" (no prolems here)
msbuild Car.EnquiryPresenter.csproj
throws error: "error MSB4066: The attribute "Version" in element is unrecognized."
I can see here that the dotnet cli is not yet supported
https://jira.sonarsource.com/browse/SONARMSBRU-310
But this post suggests that it is possible:
https://www.sonarsource.com/resources/product-news/news.html#2017-04-13-sonarqube-scanner-for-msbuild-2-3-released
'support for .NET Core projects: SONARMSBRU-167'
But I've been unable to get this to work.
Can anyone help?
Yes is the answer (great, I get to answer my own question!).
I've just got it working using v15 of MSBuild, but I needed to fully qlaulify the path to the exe, otherwise it continued to use v14:
MSBuild.SonarQube.Runner.exe begin /key:"Car.Enquiry-Presenter" /name:"Car.Enquiry-Presenter" /version:"1.0"
"../../../../Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe"
MSBuild.SonarQube.Runner.exe end
I also needed to add a 'ProjectGuid' node to my csproj file containing a guid (i just generated that with https://www.guidgen.com/)
NB: Overriding the toolset you use in the csproj file does not force it to use v15. ie: ... .
Hence the fully qualified path.
you need to ensure that the nuget packages are updated using a "dotnet restore" before calling msbuild.exe too.

SonarQube failing to analyze auto-generated target framework moniker files

I'm using SonarQube 5.2 and MSBuild.SonarQube.Runner to analyze a solution containing a number of C# projects. When the runner encounters auto-generated files like...
bin\Release\.NETFramework,Version=v4.5.AssemblyAttributes.cs
bin\Release\.NETPortable,Version=v4.5,Profile=Profile7.AssemblyAttributes.cs
...it fails with the following error...
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.runner.Main.executeTask(Main.java:70)
at org.sonar.runner.Main.execute(Main.java:59)
at org.sonar.runner.Main.main(Main.java:53)
Caused by: java.lang.IllegalStateException: The folder 'C:\Source\Project1\bin\Release\.NETFramework' does not exist for 'TheProject:TheBranch:TheProject:TheBranch:GUID' (base directory = C:\Source\Project1)
At the moment I'm working around the problem by deleting those files before invoking the runner with the 'end' verb, but would like to know if there is a better way or if this is a known bug.
Can anyone tell me if SonarQube should be able to handle these files, or if there is a configuration I should tweak to avoid the problem?
This isn't a known issue - thanks for reporting it. I've created SONARMSBRU-199 to track it.
Normally XXXAssemblyInfo.cs files are generated under the %TEMP% directory so they are automatically excluded from the analysis as they are not under the project folder. However, it's a valid file name so it should be possible to analyse it if it happens to be created under the project directory.

VS2012 automated deployment - OutputPath property is not set for project

Ok, I know this has been asked a bunch of times...
I have tried to change the configuration and the outputPath, but still I have this issue.
I am setting up automated build and deployment for our product.
We have a single solution file and multiple projects within it.
Using VS2012 and the default build definition, I have set the "Items to build" to a single project - the one we wish to have build and deployment for.
Lets call this project "Forms".
When I run the build definition, it builds and says success. However, it gives a warning:
$/XXX/TRUNK/XXX/Forms.Web/Forms.Web.csproj - 0 error(s), 1 warning(s),
View Log File
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets
(610): The OutputPath property is not set for project
'Forms.Web.csproj'. Please check to make sure that you have specified
a valid combination of Configuration and Platform for this project.
Configuration='Release' Platform='Any CPU'. You may be seeing this
message because you are trying to build a project without a solution
file, and have specified a non-default Configuration or Platform that
doesn't exist for this project.
I have checked the .csproj file and there is a property group with the OutputPath specified.
I've also tried various combinations of configuration/platform, but the issue remains.
Does anyone have any idea what could cause this? It's driving me nuts. Without this fixed, no deployment is done... It seems to only build and doesn't even generate the .DLL files.
Try to delete the "Platform" environment variable.
(Visual Studio use this environment variable, which is possibly wrong.)
Then restart VS, and re-build the solution...

Categories

Resources