Your project is not referencing the ".NETPortable,Version=v4.5,Profile=Profile78" - msbuild

When i build my PCL project i received the following error:
Microsoft.NuGet.targets(186, 5): [null] Your project is not referencing the ".NETPortable,Version=v4.5,Profile=Profile78" framework. Add a reference to ".NETPortable,Version=v4.5,Profile=Profile78" in the "frameworks" section of your project.json, and then re-run NuGet restore.

Following error appears when you have .netstandard project in same directory and build it once.
It leaves .json files in Obj directory and it breaks PCL project build.
Move .netstandard .csproj out of this directory and remove Bin and Obj directories.

Related

System.Management.dll not being copied to output directory .net 6 c#

There is an error System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'.I figured when the System.Management.dll is in the output directory, the error will be gone.
It is reference using NuGet but I couldn't get libraries in NuGet to be copied to the output folder. So I thought of adding the physical System.Management.dll file into my project and and reference it as assemblies (right-click project -> Add Reference -> browse to library) thenset 'Copy Local' to True. However, the dll still won't get copied over to the output folder.
The application is on .Net 6. Is there a reason behind why I can't copy this library like other?
A .NET6 project would normally use System.Management version 6.0.0.
The error suggests that there is another package in your project that explicitly depends on 4.0.0.
Without knowing the specifics of you projects, I suggest:
inspecting the build output for warnings about package version,
upgrading 3rd party packages in your solution.
Figured out I could copy nuget package references to output directory by setting this attribute in the project file
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
Then the nuget referenced packages will be copied to the output directory.

How to make .nuproj projects work with NCrunch

I have a solution with two nuproj projects, say A and B.
Both projects contain only props and targets files (so NO assemblies or PDB files) and they both generate NuGet packages.
Now, A has no reference and it is an internal dependency, whereas B references A plus other external NuGets.
Then I have an MSTest project that dynamically invokes MSBuild on a project which references B.
All works fine in Visual Studio and the tests pass. However, NCrunch compiles with warnings for the project B.
WARNING - ........\program files (x86)\microsoft visual studio\2017\professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets (2110, 5): MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'A.nupckg' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Infact, no NuGet package is generated for the A project in the NCrunch solution directory (the package is correctly generated in Visual Studio).
I have also tried to set the following properties for the A and B projects:
Instrument assembly = false
Prevent signing of output assembly = false
Implicit project dependencies = true
nothing changes and the warning is still there and no NuGet is generated for the A project (all the source files and dependent assemblies are in the NCrunch solution folder).
And Copy referenced assemblies to workspace is set to true.
Is there any known issue with using NCrunch with .nuproj?

error MSB4057: The target "pack" does not exist in the project when I create nuget package with MSBuild

When I create a nuget package based on this document with Visual Studio 2017. I can create the nuget package from the Visual Studio, but I failed when I create the nuget with MSBuild command line:
msbuild /t:pack
The error info:
MSB4057: The target "pack" does not exist in the project.
I have search this thread and this thread, but none of them resolve my issue.
So I do not know how to fix this issue, Any suggestions?
error MSB4057: The target “pack” does not exist in the project when I create nuget package with MSBuild
It seems you are using the .sln solution path instead of the .csproj project path when you packing your package with MSBuild.
Since the package metadata is contained directly in the .csproj file, so you should switch the .sln solution path to the appropriate .csproj project path.
The command looks like:
msbuild "YourProjectPath\xxxx.csproj" /t:pack /p:Configuration=Release
Hope this helps.

In which file do you set nuget packages for a .NET Core project?

I found something called "MyProjectName.deps.json" in the "bin" directory. But if i delete the "bin" directory and build my project again it gets created again. Where does VisualStudio pull this data from (which packages should be included in the project)?
This is based upon the obj\project.assets.json file (generated by NuGet restore) which defines inputs to the build logic that are used for the generation of the .deps.json file, along with other references from the project file.

Team city build with NuGet packages

I have set up a build in team city, with a NuGet package reference in the test project.
The folder structre I have used is
\
|- Project1
\- Project1.csproj
|- Project1.Test
\- Project1.Test.csproj
|- packages
\- lib
\- RhinoMocks
The Project1 project builds sucessfully, but the Test project fails on the ResolveAssemblyReferences step. The relative path seems to be incorrect.
[13:16:55]: [ResolveAssemblyReference] C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360, 9): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Rhino.Mocks, Version=3.6.0.0, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
[13:16:55]: [ResolveAssemblyReference] For SearchPath "{HintPathFromItem}".
[13:16:55]: [ResolveAssemblyReference] Considered "..\packages\RhinoMocks.3.6\lib\Rhino.Mocks.dll", but it didn't exist.
TeamCity build config:
MSBuild task
Build file path: Project1.Test\Project.Test.csproj
Working directory: %system.teamcity.build.checkoutDir%\Project1.Test
VCS root points to the root of the folder structure above.
As far I can tell this may be a MSBuild issue, I get the same error when I run MSBuild at the command line in the checkout folder on the build agent.
More info:
The hint path is being provided by the Nuget package configuration. Within Visual Studio the package reference works correctly. However, when running via MSBuild, it seems confused about its current directory. The ..\packages... path is actually the verbatim reference path from Nuget.
I'm confused about this part of your project structure:
|- packages
\- lib
\- RhinoMocks
This shouldn't be necessary if you're pulling the packages in from NuGet. The only file under "packages" that should be checked into source control is repositories.config.
Also, when TeamCity runs MSBuild, how are you downloading the relevant NuGet dependencies? Is it via the TeamCity "NuGet Installer" or have you configured your Solution/Projects to auto run nuget install?
You've got a mixed reference, with a strong assembly name (the Version etc.) and a hint path. If the assembly is in the GAC on your machine, it will be located even if the hint path is wrong. If it isn't in the GAC on the build machine, it can't be found. Check in your project file and see if the HintPath metadata on the Reference is the correct path (looks like it should be "..\packages\lib\RhinoMocks..." instead of what appears in the output.
That's a bunch of ifs, for any more ideas I'd need to see what's inside the project file that is failing.