Wednesday, May 20, 2020

DevOps error: No element in the source document matches '/configuration/system.identityModel'

set EnableADPublish to false in publishing profile

Reference:

Unable to restore organization's internal nuget package in devops

My company has its own nuget feed and we were facing issues while using packages in the feed in other repositories.

 

To be able to build such a project on devops, several configurations are required.

 

1.      Nuget Feed Configurations

a.       Allow collection scoped builds for the project

                                                  i.      On the project consuming the artifact, click the settings Gear in bottom-left of screen, then click settings in the 'Pipelines' section

                                                ii.      Ensure that 'Limit Job authorization scope to current project' is turned off

b.      Set the Pipeline's build job to use a Project Collection scope

                                                  i.      Click 'Pipelines' under 'Pipelines' in the main Navigation on the left

                                                ii.      Choose your pipeline and click 'Edit'.

                                              iii.      Click the 'Options' tab at the top then choose 'Project Collection' under 'Build job authorization scope' on the right

c.       Set permissions on the artifact

                                                  i.      Click on the 'Artifacts' icon on the far left nav, choose your artifact in the dropdown, then click the cog on the top-right

                                                ii.      Click on the permissions tab and ensure that 'Project Collection Build Service (<project collection name>)' has appropriate permissions (mine are set at 'Contributor' and that seems to work)

2.      Project configuration in visual studio

a.       Add nuget.config in the project and add a package source to your organization's nuget feed

b.      Add referenced dlls to source control

                                                  i.      Click on view all files in solution explorer

                                                ii.      Nuget restore on solution

                                              iii.      Build solution

                                              iv.      Expand bin/debug or bin/release folder depending on the intended release configuration in devops pipeline (better yet, both)

                                                v.      Right click on the referenced dll and click ‘Add ignored items to source control’ command

                                              vi.      Check in and sync the project with devops repo

3.      Pipeline configurations in devops

a.       Edit devops pipeline’s restore nuget packages task

                                                  i.      Set ‘Feeds to use’ setting to ‘Feeds in my nuget.config’

                                                ii.      Select ‘Path to nuget.config’ as the path to added nuget.config file

Use nuget.config in the project and add a package source to your organization's nuget feed

In devops nuget restore taksk mention set 'Feeds to Use' as 'Feeds in my nuget.config' and select the added nuget.config file

 

References:

https://developercommunity.visualstudio.com/content/problem/795493/403-error-during-nuget-restore.html




Friday, May 15, 2020

DevOps Visual Studio Build Could Not resolve reference


Although my project could build fine without any errors on laptop, devops visual studio build task could not resolve reference of NewtonSoft.Json nuget package for some reason.

Actual warning was:

Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

Which further caused build to fail with error:

The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

Such errors can be resolved by adding the related .dll files to source control. 

The details steps are:

  1. Build the solution in laptop.
  2. Select the project which fails to build
  3. In the solution explorer click on show all files at the top.

  4. Then expand bin/debug or bin/release folders
  5. Right click on Newtonsoft.Json.dll and select 'Add Ignored File to Source Control' command.
  6. Right click again on the file and select 'Include in Project' command.
  7. Lastly check in the project and build on devops



Update: There are some more related errors which can be solved in a similary way

Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.




Could not load file or assembly 'Microsoft.IdentityModel.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca' or one of its dependencies. The system cannot find the file specified.




Tuesday, May 5, 2020

Package 'AppForSharePoint16WebToolkit.4.0.0' is not found on source 'https://api.nuget.org/v3/index.json'.

For some reason, when we create a new sharepoint provider hosted app in visual studio it adds a reference to the package 'AppForSharePoint16WebToolkit.4.0.0'. This package is no longer available on nuget and the latest stable version is 'AppForSharePoint16WebToolkit.3.1.5'. So to rectify this error we need to uninstall this package and reinstall the available version which is fairly straightforward.

However, when we compile the solution after replacing the package, we get another error that 'SecurityTokenException' class is not available (in SharePointContext.cs file). This error can be easily fixed by replacing 'SecurityTokenException' with 'SecurityTokenExpiredException'

SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...