.net MAUI can't build due to not found target in project.assets.json - .net-maui

I have a .net maui app that I migrated from Xamarin Forms. I can build fine on Azure DevOps and on my Mac. But when I try to build it on Windows in Visual Studio I get this error message:
Assets file '..obj\project.assets.json' doesn't have a target for 'net6.0-android'. Ensure that restore has run and that you have included 'net6.0-android' in the TargetFrameworks for your project.
Assets file '..obj\project.assets.json' doesn't have a target for 'net6.0-windows10.0.22621.0'. Ensure that restore has run and that you have included 'net6.0-windows10.0.22621.0' in the TargetFrameworks for your project.
Assets file '..obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project.
Assets file '..obj\project.assets.json' doesn't have a target for 'net6.0-ios'. Ensure that restore has run and that you have included 'net6.0-ios' in the TargetFrameworks for your project.
My csproj looks like this. I tried to compare that to a project generated from the template (which I can build fine), and remove differences but the error did stay the same.
<PropertyGroup>
<TargetFrameworks>net6.0-ios;net6.0-android;net6.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.22621.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.22621.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<OutputType>Library</OutputType>
</PropertyGroup>
I did try to clean, delete obj and bin folders and reinstall the .net maui workload, but without success. Any idea what that is?
EDIT:
I think the problem was caused by my try to make the version conditional to non-ios platforms with this:
<ApplicationDisplayVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios'" >7.8.12844</ApplicationDisplayVersion>
<ApplicationVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios'">2022092726</ApplicationVersion>
Once I moved that to a separate sectio it the build works again.
<PropertyGroup Condition="$(TargetFramework.Contains('-android')) and '$(Configuration)' == 'Release'">
<ApplicationDisplayVersion>7.8.12844</ApplicationDisplayVersion>
<ApplicationVersion>2022092726</ApplicationVersion>
</PropertyGroup>

Usually when this happens, your restore command was not called, interrupted, or threw some error. In any case, the issue is not with your VS but your solution.
What you need to do is really simple:
Open your solution and clean build. The same error should be thrown
Close it and remove the newly created bin and obj
Open VS again and go to terminal/cmd and on your solution level call dotnet restore.
After that's complete right click on the solution and restore your NuGet packages and your app should now be able to compile and run

Related

The target "PipelineTransformPhase" does not exist in the project

I'm trying to create an azure package via tfs build server.
my project is an Azure MVC web api project. when i trigger a build I get the error "The target "PipelineTransformPhase" does not exist in the project."
But I've added the Microsoft.WebApplication.targets file to the appropriate folder in my build server.
this is the line mentioned in my csproj file
Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' == ''" />
even without condition I get the same error.
could someone help to resolve this issue .
many thanks in advance
First, read these SO posts, they might have your answer:
Package / Publish error on Azure
MSBuild target package not found
Is it possible that the .targets file was never found? (If you're on a machine without Visual Studio it won't be there). That would produce an error somewhat like:
The imported project
"...\WebApplications\Microsoft.WebApplication.targets" was not found.
Confirm that the path in the <Import> declaration is correct, and that
the file exists on disk.
I'll assume that isn't the problem. I would run the build with logging enabled and look at where your targets are coming from (or not coming from in this case). It might add some light to your problem. You can use the /fl switch something like my example below to get a detailed (not diagnostic -- which you could do) log from a build:
msbuild /fl /flp:logfile=<yourpath>\yourLog.log;verbosity=detailed
The lines you should be most interested in are around targets. Lines like
Target "Clean" in file "..." from project "..." (entry point): and
Overriding target "Clean" in project "..." with target "Clean" from project "..."

Deploy silverlight xaps to ClientBin in WSP

I have some xaps being built by other projects in my solution and I need the xaps to be included in the resulting WSP.
I have a mapped folder Layouts with a sub-folder ClientBin and then in the csproj I have the following:
<ItemGroup>
...
<Folder Include="Layouts\ClientBin\" />
...
<Content Include="Layouts\ClientBin\*.xap" />
</ItemGroup>
...
<Target Name="BeforeLayout">
<ItemGroup>
<XAPFiles Include="..\..\out\$(Configuration)\bin\sl\xap\**\*.xap" />
</ItemGroup>
<Copy SourceFiles="#(XAPFiles)" DestinationFolder="Layouts\ClientBin" OverwriteReadOnlyFiles="true" />
</Target>
When I delete the xaps from the destination folder and open the SP project in VS the package manager shows the layouts folder with nothing in it. And then when I build none of the xaps get packaged in the WSP but the copy operation worked local to the project. If I rebuild nothing changes. If I unload and reload the project then build, the WSP does contain the files I need.
This works for my dev box because I can make sure I'm performing all these steps to keep the package manager happy, but it doesn't work on the team build machine. Are there steps I can take to make sure the package manager grabs those xaps or even other ways to achieve what I'm trying to do?
I created empty placeholders in Layouts\ClientBin for all the xaps to be copied.
This wasn't optimal since it required some manual dependency management, but it works.
The end result is that the package manager is aware of those files existing when you open the project in VS and that they need to be packaged up into the WSP. The copy operation works as before but now the new files are packaged.

Unable to install TypeScript in Visual Studio 2012 Professional update 3

I'm unable to install/use TypeScript (version 0.9.1.1) in Visual Studio 2012 Professional update 4 on a Windows 7 machine.
After "successful install" TypeScript doesn't show in the Tools, Extension and Updates. I'm not able to add a new item with .ts extension to an MVC4 project. When I try to add a .ts file, VS adds a .cs file.
Thanks in advance for your help.
Okay, the templates were installed; just hard to find.
Add > New Item, then search for Typescript in the top-right search box. Came up with the "TypeScript file" type.
Since Web Essentials dropped the support to compile ts files to js files, I found this link helpful: http://typescript.codeplex.com/wikipage?title=Compile-on-Save
I didn't have to do the following first step as it was already in the csproj file.
<TypeScriptCompile Include="MyFile.ts" />
After unloading the MVC project, I'd to add the following at the end of the csproj file (still within the project element):
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES3</TypeScriptTarget>
<TypeScriptRemoveComments>false</TypeScriptRemoveComments>
<TypeScriptSourceMap>true</TypeScriptSourceMap>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TypeScriptTarget>ES3</TypeScriptTarget>
<TypeScriptRemoveComments>true</TypeScriptRemoveComments>
<TypeScriptSourceMap>false</TypeScriptSourceMap>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
MyFile.ts was in the /scripts folder. I added a script reference to the file in my view:
#section scripts {
<script type="text/javascript" src="~/Scripts/MyFile.js"></script>
}
Everything worked at this point.

How to build mutiple web deployment packages in a VS2012 solution file

I can find plenty of examples of building a single web deployment package from a project file but I want to use the same technique in an automated build environment. When I try to specify the parameter as an msbuild argument I end up with packages created in the /obj directory. I want to specify the output location as a folder into which all project files in solution will be created but this isn't working for some reason?
I just worked this out based on a post from Sayed Ibrahim Hashimi I adpated the approach as outlined below
<PropertyGroup>
<DeployOnBuild Condition=" '$(BuildPackages)'!='' ">$(BuildPackages)</DeployOnBuild>
<DesktopBuildPackageLocation Condition=" '$(BuildPackages)'!='' ">$(DeployPackageLocation)\$(AssemblyName)\$(AssemblyName).zip</DesktopBuildPackageLocation>
</PropertyGroup>
Basically adding the BuildPackages and DeployPackageLocation mean that a root location for deployment packages can be controlled by a solution/global parameter and a build level switch like below
> MSBUILD <SolutionPath>.sln /P:Configuration=Release /P:Platform="Any CPU" /P:BuildPackages=true /P:DeployPackageLocation="<YourOutputLocation>"
There are more details on my blog

VS2012 MSBuild: Publish a Web Application Project with Existing Publish Profile

In the Visual Studio 2012 Build menu, there's a Publish command. In this you can establish profiles which are saved as .pubxml files in the Properties folder of the Project. I have one such profile that's a simple file copy operation - it just compiles the site and dumps it to a folder.
How can I use msbuild at the command line to publish a compiled web application to a folder?
What I've tried
I've tried the example from this question:
After Publish event in Visual Studio
And the changes and examples given here:
http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild
The latter seems to get closest, but it causes every library Project the .csproj I'm attempting to publish from to throw an error:
Project "MainProj.csproj" (1) is building "ReferencedProj.csproj" (2) on node 1 (default targets).
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(609,5): error : The OutputPath property is not set for project 'ReferencedProj.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Staging' Platform='AnyCPU'. 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. [ReferencedProj.csproj]
Done Building Project "ReferencedProj.csproj" (default targets) -- FAILED.
This approach is very similar to what's suggested in this answer:
https://stackoverflow.com/a/7077178/176877
The crucial difference may be that I'm in Visual Studio 2012, rather than VS2008 or 2010.
Old question, but in case this helps anyone, this simple, stripped back approach worked fine for me:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
...
<BuildDependsOn>
$(BuildDependsOn);
PublishOtherProject;
</BuildDependsOn>
</PropertyGroup>
<Target Name="PublishOtherProject">
<MSBuild Projects="pathtomyproject.csproj" Properties="DeployOnBuild=true;PublishProfile=nameOfPublishProfile" />
</Target>
The key line being:
<MSBuild Projects="pathtomyproject.csproj" Properties="DeployOnBuild=true;PublishProfile=nameOfPublishProfile" />

Resources