Remove a package via script in xamarin forms - shell

I have a build build script(MyBuild.sh) set up for creating the Android apk for a xamarin forms application.
My requirement is when i give the internal test builds i want the microsoft app center crashes and analytics in the the project csproj but when i take the PROD builds i don't want the microsoft app center crashes and analytics in the project
so in the build script i check whether its a PROD build and tried to remove the app center packages from the csproj.
if [ $Env == 'PROD' ]
then
dotnet remove ./Sample/Sample.csproj package Microsoft.AppCenter.Analytics
dotnet remove ./Droid/Sample.Droid.csproj package Microsoft.AppCenter.Crashes
fi
My problem is when the script is executed it correctly removes the package from the Shared Code but not from the Droid.csproj and while trying to remove the package it throws
info : Removing PackageReference for package 'Microsoft.AppCenter.Crashes' from project './Droid/Sample.Droid.csproj'.
error: The imported project "/usr/local/share/dotnet/sdk/2.1.4/Xamarin/Android/Xamarin.Android.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. /Users/george.thomas/Documents/Nov/Candidate/Droid/Sample.Droid.csproj
Now if i remove the MSBuildExtensionsPath from the Droid.csproj and run the script it correctly removes the packages but the project cant be built
throwning The target "Build" does not exist in the project
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />

Related

Including Nuget Content Files to Target Projects Publish on .net Core Project

before i start i must state that i pretty new to this nuget package things, so come basic at me.
My app has a core project to carry some .dll and .sql files and an api project. I have made the core project a nuget package with dotnet pack and automated it on github action so it creates a new version at all prs and pushes it to my private nuget server and it is all fine till here.
When i install this core package to my api project, there is no problem either. It installs successfully and my sql files shows up on the target project as i expected(but as linked sources).
But when i try to publish this project with dotnet pack, the .sql files are not copied to output folder. I looked to the properties of the files and saw that their copy to output directory prop has been reset to do not copy and the file path was absolute.
My goal is to build and deploy this api with github actions so absolute paths are not acceptable and besides i don't want to arrange something in the target project manually.
I'm packing the core project with dotnet pack
I don't have any
.nuspec file
package config xml
nuget config
package metadata
or other things like than and i don't know how to use them.
I have tried adding to csproj file <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> and <RestoreProjectStyle>PackageReference</RestoreProjectStyle> things and they did not work.
I have tried adding to csproj file
and it did not work too.
Can anyone help me?
The only thing you need to do is that you should write this node <PackageCopyToOutput>true</PackageCopyToOutput> to every content file of the nuget net core project:
<ItemGroup>
<Content Include="Queries\Account\CheckAccountRef.sql">
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
.....
</ItemGroup>
Then, re-pack your nuget project with dotnet pack and then reinstall this new version into your main project. Before you install, you should delete the old caches under C:\Users\xxx\.nuget\packages.
There is a similar issue about this.
You can use .nuspec file to configure all your dependencies. Please refer https://learn.microsoft.com/en-us/nuget/reference/nuspec

TFS 2015 Visual Studio Build - Package .zip not being created

I'm trying to build my solution and package up the web app into a web deploy (.zip) package to be deployed.
I've added the Visual Studio Build step with the following MSBuild Arguments:
/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
And I've set up the Copy and Publish Build Artifacts step to copy all .zip files to the drop folder.
The build completes successfully but nothing is copied to the drop folder because there are no .zip packages that get created.
So when I look on the TFS server, the only thing in the 'a' folder is an empty 'drop' folder. And in the 's' folder is the solution directory with a PrecompiledWeb folder in it. Not sure what that is but it doesn't look like the deployment package (and it's not a .zip).
Any ideas?
I have tried the same on VS2015 MVC web application using VSTS and TFS 2015.2.1 both. I had to do a slight change to the Build arguments in Visual Studio build. That is removing the trailing "\" in /p:PackageLocation="$(build.artifactstagingdirectory)\".
Here is the argument I passed to Visual studio build step
/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)"
Then I used Copy and Published Build Artifacts (Deprecated in VSTS you should use Copy task and Publish task instead of this task) as shown below
This gives me output as below.
First suggest you manually remote in the build agent and build the project through MSBuild command line with arguments to see if the project builds properly.
This will narrow down the issue is related to the environment on your build agent or your build definition.
You should directly use /p:PackageLocation=$(build.stagingDirectory
Besides since you have multiple assemblies that are referenced in the web app. Please also double check dependencies that are building in the correct order or referenced correctly.
Make sure the ASP.NET development workload of Visual Studio is installed.
If DeployOnBuild is having no effect, you may need to install the ASP.NET Development "workload" with the VS setup tool.
There are specific .targets files that, if they don't exist, cause these parameters to be silently ignored. Installing this adds those .targets and the parameters become active, allowing the .zip to be created.
For me (VS 2017) the relevant target file (or one of them, anyway) that was missing but is needed is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets
If it is missing, you'll need to install as above, and if it is there, then you have a different problem. ;)

Deploy Azure WebJob using VSTS

I'm having some issues deploying an Azure WebJob using Visual Studio Team Services (VSTS).
The WebJob seems to be deployed successfully but it breaks the Azure website that is hosted in the same App Service! I don't have this problem if I deploy using VS2013.
This is my build task that generates the WebJob deployment package:
And this is my deployment task:
There are no errors when I deploy the Azure WebJob. If I go to the Azure Portal I see the WebJob is there, and it runs successfully. WebJob files are copied into the wwwroot\App_Data\jobs\triggered\RemoveExpiredDids folder as expected, but the problem is that some other files will be copied into the wwwroot\App_Data\bin folder, which will break the existing website that was already deployed into that App Service!!!
So I decided to find out why this was happening. After downloading and extracting the deployment package I saw there are 2 folders (app_data and bin) and the scheduler file (settings.job):
This explains why some assemblies are coppied into the wwwroot\App_Data\bin of the App Service. The strange thing is that this doesn't happen when deploying from VS2013!!! I took a look into the MSBuild log and found the following line:
Object dirPath ([app service name]\bin) skipped due to skip directive 'SkipBinFolderOnDeploy'.
Concluding, bin folder is included when deploying the Azure WebJob from VSTS but is excluded when deploying it from VS2013.
So my question is: how to prevent the bin folder from being deployed when using VSTS? Is there any MSBuild parameter/flag to do this?
I've had issue with this particular problem as well.
The latest method I found is using Web Deploy Operation Settings , -skip:Directory= (in this case it would be -skip:Directory='\\bin') when you create your azure deploy task in the release definition (Additional arguments). I've seen that this indeed excludes the bin folder from the update actions (result).
Let me know if this helps you in any way.
Refer to these ways to deploy webjob to azure:
Modify Visual Studio Build task to deploy webjob with FileSystem (MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\WebJob" /p:DeployDefaultTarget=WebPublish)
Add Delete Files task to release definition to delete bin folder (Source Folder: $(System.DefaultWorkingDirectory)/WebJobVnext/drop/WebJob); Contents:bin)
Modify Azure App Service Deploy task (1. Uncheck Publish using Web Deploy option. 2. Package or folder: $(System.DefaultWorkingDirectory)/[artifact name] /drop/WebJob)
I was finally able to fix it, thanks #starain-MSFT for pointing me in the right direction. I had to make some minor changes, though. This is the task that creates the deployment package:
MSBuild arguments:
/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:DeployDefaultTarget=WebPublish /p:Configuration=$(BuildConfiguration) /p:OutputPath=.\bin\ /p:publishUrl="$(build.artifactstagingdirectory)\temp\WebJob"
The difference here comparing to #starain-MSFT answer is that I had to add the /p:OutputPath= parameter, otherwise I'd get the following error:
The OutputPath property is not set for project
After generating the package, I delete the bin folder and zip it (this reduces the build time).
This is my deployment task:
Please note that $(DeploymentPackagePath) is the path to the zip file that contains the deployment package, as mentioned before. It doesn't matter if you deploy the package as a zip file or if you unzip it and deploy the folder, it works both ways.

How can I run Xamarin.Forms in my project from it's source, so I can set breakpoints etc in Xamarin.Froms

I want to be able to run Xamarin.Forms from source so I can set breakpoints etc in it. I want to do this primarily so I can see how things get called so I can better understand how it works in response to my use of it in my app. I don't want to do it in the final app, I'd just like to swap out the source version for the nuget package in the end. During development though I would like to see how it runs things to better understand how I can manipulate/override/implement different details.
So far I am close to getting it to compile with my project, but I get 2 build issues realated to Xamarin.Forms.Conrols.Issues I think they are just unit tests, but it stops the build.
/Users/username/github/Xamarin/Xamarin.Forms/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39636.xaml: Error: Object reference not set to an instance of an object (Xamarin.Forms.Controls)
And
/Users/username/github/Xamarin/Xamarin.Forms/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/PlatformSpecifics_iOSTranslucentNavBarX.xaml: Error: Object reference not set to an instance of an object (Xamarin.Forms.Controls)
Maybe there is a better way to run it from source and have it integrate with a project and I am just missing it?
These are the projects I have added to my project in a Solution Folder:
Maybe I am on the right path, maybe not. Currently I am only targeting iOS I have an Android project but I am not concerned with that at the moment, just trying to limit it to running on iOS. If that's an issue I can definitely change it. It shouldn't care about the Android parts if I am building for iOS only. Maybe it does?
... LATER ...
Ok tinkering some more I got it down to these packages:
When I right click on the solution folder and select: "Build Xamarin.Forms" the build succeeds. It only fails now with the following error when I try to build my app's Form's project:
/Users/username/github/Xamarin/MyProject/App.xaml.cs(13,13): Error CS0103: The name 'InitializeComponent' does not exist in the current context (CS0103) (MyProject)
I get 51 errors whenever it references anything inside Xamarin.Forms or when it's trying to access a x:Name in some XAML from the code behind.
Intellisense sees the method as well, in this case InitializeComponent so at least that seems to know about it.
Ok, I got it. Here's how I did it:
Clone the Xamarin.Formsrepo from github:
https://github.com/xamarin/Xamarin.Forms
The following applies to Xamarin.Forms 2.3.4.247
cd into the newly cloned repo and checkout that tag corresponding to Xamarin Forms v2.3.4.247:
$ git clone git#github.com:xamarin/Xamarin.Forms.git
$ cd Xamarin.Forms
$ git checkout 2.3.4-2
Add these projects into your project. I placed them in a new solution folder within the project in Visual Studio Mac. I was only concerned with iOS. It would be similar for Android, just adding those specific libs. To figure how the dependencies I just opened the Xamarin.Forms.sln file and check each project's references.
Xamarin.Forms.Platform
Xamarin.Forms.Core
Xamarin.Forms.Platform.iOS
Xamarin.Forms.Xaml
Xamarin.Forms.Build.Tasks
Xamarin.Forms.Xaml.Xamlc
Xamarin.Forms.Xaml.Xamlg
Next, update packages for Xamarin.Forms.Build.Tasks (Mono.Cecil is missing when you import this project. It has a little warning icon by it in the packages list UI)
Now cd to your project folder and copy the .nu* files from the Xamarin.Forms Repo:
$ ls -1
Xamarin.Forms
YourProject
$ cd YourProject
$ cp -r ../Xamarin.Forms/.nu* ./
Afterwards, in the following to csprojfiles (The forms project and the platform project):
YourProject/YourProject/YourProject.csproj
YourProject/iOS/SourceTest.iOS.csproj
file add the following <Import> at the bottom before </Project>:
<Import Project="..\.nuspec\Xamarin.Forms.targets" Condition="Exists('..\.nuspec\Xamarin.Forms.targets')" />
Note this is referencing the files we copied above.
Finally it's time to add the references in Visual Studio to both projects.
Forms Project
Platform Project
That's it. It should compile now and you can add breakpoints into Xamarin.Forms and see how things run. Be sure you added that <Import> node above to ALL csproj files using Xamarin.Forms. From the looks of it, It's responsible for triggering XamlC to process the XAML. When you install Xamarin.Forms from Nuget, it adds this for you. Also be sure you have copied the *.nu files mentioned above to the root of your solution directory.
Remember, once you are done tinkering and you decide to install the Nuget Xamarin.Forms package, you may need to undo some of the changes you made above. For example, check the csproj files to be sure the <Import> is only from the package install.
In case you get compiler errors, check the Xamarin project references. Here are the individual Xamarin related inter-project dependencies that I used to generate the project reference list above.
Xamarin.Forms.Core
References
Xamarin.Forms.Platform
Xamarin.Forms.Platform
References
None
Xamarin.Forms.Platform.iOS
References
Xamarin.Forms.Core
Xamarin.Forms.Xaml
References
Xamarin.Forms.Core
Xamarin.Forms.Xaml.Xamlc
References
Xamarin.Forms.Build.Tasks
Xamarin.Forms.Xaml.Xamlg
References
Xamarin.Forms.Build.Tasks
Xamarin.Forms.Build.Tasks
References
Xamarin.Forms.Core
Xamarin.Forms.Xaml
In addition to AJ Venturella's answer, you also need in 2022:
...
<Import Project="..\..\.nuspec\Xamarin.Forms.targets" />
<Import Project="..\..\.nuspec\Xamarin.Forms.props" />
<Import Project="..\..\.nuspec\Xamarin.Forms.DefaultItems.targets" />
<Import Project="..\..\.nuspec\Xamarin.Forms.DefaultItems.props" />
</Project>
Open .nuspec\Xamarin.Forms.nuspec and check the content that targets "build". It's what's above.

VS2017 MSB4057 The target "CreateManifestResourceNames" does not exist in the project

When VS2017 was used to create a stateful solution, producing the standard boilerplate code, the resulting two projects have two different MSBuild versions.
The application uses MSBuild version 1.5.0.
The service uses MSBuild version 1.6.0 (the current "latest").
If I run the solution this way, it runs fine on my local Service Fabric cluster.
But when after I use NuGet to update the application's MSBuild to 1.6.0 (so both application and server projects use the same), the following errors occur.
Severity Code Description Project File Line Suppression State
Error The OutputPath property is not set for project 'gt_strd5.sfproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' P follow a project-to-project reference to this project, this project has belatform='x64'. This error may also appear if some other project is trying toen unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform. gt_strd5 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 737
Severity Code Description Project File Line Suppression State
Error MSB4057 The target "CreateManifestResourceNames" does not exist in the project. gt_strd5 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 2630
I found that after the change, some references in the application's project file continued to reference MSBuild 1.5.0. In my case, the gt_strd5.sfproj file contained four references which needed to be updated from 1.5.0 to 1.6.0. See the snippets from the XML below.
Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.**MSBuild.1.5.0**\build\Microsoft.VisualStudio.Azure.Fabric.Application.props" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.**MSBuild.1.5.0**\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')"
.....
Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.**MSBuild.1.5.0**\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.**MSBuild.1.5.0**\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')"
To verify this, I went back a couple times and was able to reproduce both the issue and this solution.
Hope it saves someone else some time.
Best Regards
I was getting this error into PCF control.
Run Developer Command Prompt VS2017/ VS2019
a) Remove white space from your folder like Test%20-%20PCFs (source control generated name) should be TestPCFs
b) Go to pcf project folder from cmd line & run msbuild /t:restore
b) Go to cds project folder from cmd line & run msbuild /t:restore
c) On cds project folder, run msbuild
d) For release deployment run msbuild /p:configuration=Release
For other types of projects
a) Remove white space from your folder name
b) run msbuild /t:restore
c) run msbuild

Resources