Summary:
I'm passing /p:ReferencePath to msbuild, when building a Xamarin.Android project. This does work with Visual Studio 2017, but not with Visual Studio 2019.
In detail:
I have two projects:
Xamarin.Forms (with main class library, iOS and Android project underneath)
Class library
The Xamarin.Forms project is referencing the class library via HintPath directly in Debug build. On the build server (Jenkins) things work differently (release build) and the library is build separately. Therefore I use ReferencePath to overwrite the stored HintPath and reference the class library (dll) on the Jenkins server, which was previously build.
The failing build command looks like this
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild"
TestJenkins/TestJenkins/TestJenkins.Android/TestJenkins.Android.csproj
/p:Configuration=Release /p:ReferencePath=C:\Jenkins\workspace\TestMSBuild\MPL1.0
/t:PackageForAndroid /t:Build /v:diag
I left out the other parts, because they do work. When reading the output log I noticed the following, when building with Visual Studio 2019:
the ResolveAssemblyReference task doesn't list the passed ReferencePath under SearchPaths= for the Android build, but it is listed for the class library build (the main library for the Xamarin.Forms project and not the separate class library)
one warning MSB3245
multiple error CS0246
On another Jenkins machine there is Visual Studio 2017 installed and the same code, the same scripts does work without an error. So the question is, what's the difference. Lately, I upgraded to .NET Standard. Perhaps I forgot something?
What I've tried:
set up a similar test project, but here it fails with error CS0103
use hard coded link to the dll with BeforeResolveReferences and this does work, but that is only a hack (continous integration should not work that way)
adding ReferencePath in csproj in Android project, but still the same errors
changed Copy local in the Android project
Visual Studio 2019 does build the project on the Jenkins server, if I update the references and use hard-coded links
read the diagnostic log (140k lines)
read the manual, but the use of RerencePath is not really explained
many more ...
Question:
As you can see I'm using the build tools of Visual Studio 2019, but I don't know what has changed to Visual Studio 2017 Build Tools. Am I calling msbuild wrong? Does /p:ReferencePath works different than I expect? Can someone give me a hint to find the cause for this?
Edit (1):
Now I found the following out: The CS0246 error point to lines in my Android project, where a using statement is made: e.g. using MyClassLibrary.Component.Feature;.
The MSB3245 warning seams to occur if the HintPath in the Android project can't be resolved.
Back to the using statement: I have an interface defined my external class library. A class in the Android project implements this. E.g.
Code in external class library:
public interface ITextService
{
string GetText();
}
Code in Android project:
using SomeLibrary; // error CS0246
using Xamarin.Forms;
[assembly: Dependency(typeof(TestJenkins.Droid.TextService))]
namespace TestJenkins.Droid
{
public class TextService : ITextService // error CS0246
{
public string GetText()
{
return SomeLibrary.ServiceClass.NativeKey;
}
}
}
The question still is, why can't the reference from the Android project be resolved?
Edit (2):
For me that must be a bug in msbuild with VS2019 or a behavior change. So I thought I can combine this with this:
<Project DefaultTargets="Build" InitialTargets="ValidateToolsDllExists" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ValidateToolsDllExists">
<Error
Text=" The ToolsDllPath property must be set on the command line."
Condition="'$(ToolsDllPath)' == ''" />
<Error
Text=" The ToolsDllPath property must be set to the full path to tools.dll."
Condition="!Exists('$(ToolsDllPath)')" />
</Target>
<Target Name="BeforeResolveReferences">
<CreateProperty
Value="$(ToolsDllPath);$(AssemblySearchPaths)">
<Output TaskParameter="Value"
PropertyName="AssemblySearchPaths" />
</CreateProperty>
</Target>
<!-- ... -->
</Project>
But passing /p:ToolsDllPath=C:\path\to\my\dll to msbuild still throws the CS0246 error.
Related
Previous title:
The "GenerateFileFromTemplate" task was not found
.NET project template - GeneratedContent
.csproj.in file transformations
The troubled package is Microsoft.DotNet.Build.Tasks.Templating.
I've created a git-repository containing multiple .NET project templates. When opened in Visual Studio, VS had a horrible performance when adding more files to the template project. This turned out to be caused by my template's project files having .csproj extension. Therefor I've changed the extensions of all my template csproj files to csproj.in.
Because of this, I need to add a msbuild task that transforms this .csproj.in to .csproj. There are several examples out on the internet:
ASP.NET Core project templates
spa-templates (Seems to use the Arcade SDK)
dotnet-template-samples (very basic)
microsoft/SEAL
In the above samples, there is no nuget.config in the project.
Your root csproj file contains a <GeneratedContentProperties> and <GeneratedContent> section:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GeneratedContentProperties>
DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework);
</GeneratedContentProperties>
</PropertyGroup>
<ItemGroup>
<GeneratedContent Include="Angular-CSharp.csproj.in" OutputPath="content/Angular-CSharp/Company.WebApplication1.csproj" />
<GeneratedContent Include="React-CSharp.csproj.in" OutputPath="content/React-CSharp/Company.WebApplication1.csproj" />
</ItemGroup>
</Project>
The .csproj.in files reference the GeneratedContentProperties:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
...
</PropertyGroup>
...
</Project>
I've tried applying the same files to my project in this commit, but I'm still getting the following error when building the project:
dotnet build --configuration Release
MSBuild version 17.3.0+92e077650 for .NET
Determining projects to restore...
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets(152,5): warning NETSDK1023: A PackageReference for 'Microsoft.DotNet.Build.Tasks.Templating' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs [C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.
IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj]
...
All projects are up-to-date for restore.
...
C:\repos\MintPlayer.AspNetCore.Templates\eng\GenerateContent.targets(27,3): error MSB4036: The "GenerateFileFromTemplate" task was not found. Check the following:
1.) The name of the task in the project file is the same as the name of the task class.
2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface.
3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files\dotnet\sdk\6.0.400" directory
[C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj]
Build FAILED.
It seems that dotnet cannot find the GenerateFileFromTemplate Task...
I also see that the spa-templates project is using the Arcade SDK, but I don't think I'd actually need that...
How can I fix this? What am I still missing here?
EDIT
When I open both projects in Visual Studio, this is what I see:
Nuget packages for my template project:
C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates> dotnet restore
Determining projects to restore...C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj : warning NU1604: Project dependency Microsoft.DotNet.Build.Tasks.Templating does not contain an inclusive lower bound.
Include a lower bound in the dependency version to ensure consistent restore results.
C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj : error NU1101: Unable to find package Microsoft.DotNet.Build.Tasks.Templating. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Local, Microsoft Visual Studio Offline Packages, nuget.org
Failed to restore C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj (in 516 ms).
Nuget packages for spa-templates:
C:\repos\spa-templates\src> dotnet restore
Determining projects to restore...
C:\repos\spa-templates\src\Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj : warning NU1603: Microsoft.DotNet.Web.Spa.ProjectTemplates.7.0 depends on Microsoft.DotNet.Build.Tasks.Templating (>= 6.0.0-beta.21373.11) but Microsoft.DotNet.Build.Tasks.Templating 6.0.0-beta.21373.11 was not found. An approximate best match of Microsoft.DotNet.Build.Tasks.Templating 6.0.0-beta.22212.5 was resolved.
All projects are up-to-date for restore.
So it seems that dotnet restore is unable to restore this package. However, the nuget sources are the same for both projects:
IdentityServer.Templates>dotnet nuget list source
Registered Sources:
1. nuget.org [Enabled]
https://api.nuget.org/v3/index.json
2. Local [Enabled]
C:\packages
3. Microsoft Visual Studio Offline Packages [Enabled]
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
C:\repos\spa-templates>dotnet nuget list source
Registered Sources:
1. nuget.org [Enabled]
https://api.nuget.org/v3/index.json
2. Local [Enabled]
C:\packages
3. Microsoft Visual Studio Offline Packages [Enabled]
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
EDIT 2
Hmm, it seems that GenerateFileFromTemplate is part of the Arcade SDK... (Howto)
How to install Microsoft.DotNet.Arcade.Sdk into the dotnet sdk folder?
It seems that the package is only available through the following NuGet feed:
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json
So I added a nuget.config in the root of the project/repository:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
</packageSources>
</configuration>
And since there's only preview versions of the package, you need for example the following version (eng/Versions.props):
<Project>
...
<PropertyGroup Label="Package versions">
<MicrosoftDotNetBuildTasksTemplatingVersion>6.0.0-beta.21373.11</MicrosoftDotNetBuildTasksTemplatingVersion>
...
</PropertyGroup>
</Project>
I am creating a new application on MAUI from scratch. The application is successfully built for Android. But when I try to build for iOS, an error occurs, the reasons for which I can not find:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.414\tools\msbuild\iOS\Xamarin.iOS.Common.targets(580,3): error MSB4044: The "CreateAssetPack" task was not given a value for the required parameter "Source".
1>Done building project "Clicker.Mobile.App.csproj" -- FAILED.
Installed all the latest updates on Macbook as well as Visual Studio (installed on Windows). The issue is reproducible on multiple computers. Most likely I'm missing something in setting up for iOS, but the error message does not give anything more informative.
CreateAssetPack task:
<CreateAssetPack
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true' And '$(EmbedOnDemandResources)' == 'false'"
ToolExe="$(ZipExe)"
ToolPath="$(ZipPath)"
Source="%(_AssetPack.Identity)"
OutputFile="$(IpaPackageDir)OnDemandResources\%(_AssetPack.DirectoryName)"
/>
I assume, judging by the compiler logs, that the _AssetPack.Identity property is empty.
I find the description of this element:
<!-- Look for the *.assetpack folders in the ODR folder -->
<CollectAssetPacks
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true' And Exists('$(_IntermediateODRDir)')"
OnDemandResourcesPath="$(_IntermediateODRDir)"
>
<Output TaskParameter="AssetPacks" ItemName="_AssetPack"/>
</CollectAssetPacks>
<ItemGroup>
<_AssetPack>
<_DirectoryName>$([System.IO.Path]::GetDirectoryName('%(Identity)'))</_DirectoryName>
</_AssetPack>
<_AssetPack>
<DirectoryName>$([System.IO.Path]::GetFileName('%(_AssetPack._DirectoryName)'))</DirectoryName>
</_AssetPack>
<_AssetPack>
<CodesignStampFile>$(DeviceSpecificOutputPath)OnDemandResources-codesign\%(DirectoryName)</CodesignStampFile>
</_AssetPack>
</ItemGroup>
But further it is not clear what needs to be specified in the project in order for this object to be initialized.
Which way to look?
I have a C# project that builds another project using Microsoft.Build library. It worked perfect until I upgraded VS to version 16.11.5. Now, I am getting the error in the logger file below when executing project.Build():
ERROR C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4693,7): The "WroteAtLeastOneFile" parameter is not supported by the "Copy" task. Verify the parameter exists on the task, and it is a gettable public instance property.
I tried manually building from VS and it works but not when building via code.
Open the Microsoft.Common.CurrentVersion.targets file and delete the folllowing element and save the file:
<Output TaskParameter =” WroteAtLeastOneFile “PropertyName =” WroteAtLeastOneFile “/>
Visual Studio 2019
C#
Project 1:
Dependencies: Meta.Numerics 4.1.4. I added Meta Numerics via the Manage NuGet Packages for Solution
Project 1 is a Class Library
Will be compiled and .dll will be shared with an associate who will use it in the main application
Project 1 builds just fine using Debug.
using System;
using Meta.Numerics;
namespace LeakDetection
{
public class LeakDetectionOperations
{
public LeakDetectionOperations(int co = 24)
{ }
public int leakCheck()
{
double result = ComplexMath.Abs(10);
return 0;
}
}
}
Project 2
Dependencies: Project 1. Imported via Add references, browser, and selected the .dll from project 1
Project 2 is just a simple test project that I'm using to test the .dll object.
It runs, but throws an exception when it attempts to call the ABS function of Meta.Numerics.
using System;
using LeakDetection;
namespace LeakTest
{
class Program
{
static void Main(string[] args)
{
LeakDetectionOperations obj = new LeakDetectionOperations();
int ret;
ret = obj.leakCheck();
Console.WriteLine("Hello World!");
}
}
}
I've followed the instructions from the Meta.Numeric gitrepo regarding installation. The installation was done as they suggested to install the package. I've also cleaned build, and rebuilt fresh. I also changed from debug to release to see if there was anything related to the debug that was causing the error. As you can see at the above code, its fairly minimum, as this is not my actual code. Its a bit more elaborate, but rather than posting the full code, this is the minimum usable code that replicates the issue I'm having. Nothing from the Meta.numeric library is usable.
I usually work in Python, have some experience in C and C++, but I have used make files to compile in linux. Using C#, visual studio is fresh for me.
Any suggestions as to where I should look would be much appreciated.
UPDATE:
Per the suggestion by #kit, I've included the .csproj file for project 1 below
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Leak_Detection</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meta.Numerics" Version="4.1.4" />
</ItemGroup>
</Project>
.csproj for project 2
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="Leak Detection">
<HintPath>..\..\Leak Detection\Leak Detection\bin\Debug\netcoreapp3.1\Leak Detection.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
I was able to kind of replicate your issue (not exactly but I got the same kind of error). I believe your test project is in .NET framework. If I do not reference any nuget package in test project, failure occurs. But, if I install any nuget package and later on uninstall it, program runs successfully. For testing, I installed and uninstalled Newtonsoft.Json package. So, there is a bug in initialization of nuget package engine for .NET framework where in absence of any nuget packages, it is not able to resolve transitive nuget dependencies. If I create test project in .NET core, test project runs without any issue.
I have also put code in github
https://github.com/dheerajjain11/MissingDLLIssue/
MetaNumerics is .NET Standard library
MetaNumericsTest is .NET Framework Test project where I installed and uninstalled nuget package. Now, it runs successfully
MetaNumerics2 is .NET Framework Test project which fails
MetaCore is dotnet core project which runs without any issue and no workarounds
I don't know if this is normal or not, but what resolved the issue for me was installing the package via the Nuget package manager on both the Library and the Console application. Both builds need a reference.
What I was doing previously, was only installing the package for the library build. Seeing how the console application was then compiling with the .dll being referenced and called, the calling application also needed the package installed.
I created a simple Windows UWP solution with windows visual studio 2019.
I did not make any changes to it but closed visual studio.
Then I wrote a simple cmake file for it.
However, it fails in "cmake --build" like this:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9):
error MC6000: Project file must include the .NET Framework assembly
'WindowsBase, PresentationCore, PresentationFramework' in the reference list.
[App1\out\App1.csproj]
When I add the requested .NET files with VS_DOTNET_REFERENCES property, there is a different error:
App1\MainPage.xaml(9,5): error MC3074: The tag 'ThemeResource' does not exist
in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.
Line 9 Position 5. [App1\out\App1.csproj]
I also tried adding all and combinations of these calls to CMakeLists.txt but they did not have any effect:
set_property (SOURCE "App.xaml" PROPERTY VS_XAML_TYPE "ApplicationDefinition")
target_compile_options (App1 PRIVATE "/langversion:default")
set_property (TARGET App1 PROPERTY DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
set_property (TARGET App1 PROPERTY WIN32_EXECUTABLE TRUE)
I cannot overcome these problems.
I generate and compile the solution like this:
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -S . -B out
cmake --build out
Cmake version is 3.14.19050301-MSVC_2.
The source files are here, including the original by visual studio created solution files and my written CMakeLIsts.txt file.
Expected result would be a cmake compiling solution which looks as much as possible like the native solution.
Probably there is just a simple error but I cannot find it.