I have a netstandard2 class library project, which contains some Roslyn analyzers. I'm trying to create NuGet package using a .nuspec and msbuild \t:pack command. All working find and i can create the nuget package easily. But as soon as i register my analyzer afteer installing the package on another project i get the following error for each analyzer in my package :
An instance of analyzer [AnalyzerName] cannot be created from [AnalyzerDllFile]: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified
Here is the .nuspec file :
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>[PackageId]</id>
<version>1.0.9</version>
<authors>Ali</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>test</description>
<!-- Solution A i found -->
<dependencies>
<group targetFramework="net46">
<dependency id="NETStandard.Library" version="2.0.0" />
</group>
</dependencies>
<!-- Solution B i found -->
<references>
<reference file="netstandard.dll" />
</references>
</metadata>
<files>
<file src="bin\Debug\netstandard2.0\[PackageName].dll" target="analyzers\dotnet\cs" />
<file src="tools\*.ps1" target="tools\" />
</files>
</package>
I tried many solution that i found on internet but seems I'm missing something else
FYI both project are targeting to .Net Framework 4.6.1
Related
i am working with Azure Pipelines recently and i have a NuGet Task inside my Build process. This progress always fails, because there is no package called "BotUtility" inside the NuGet source. That is caused because this package is created by myself and is stored in Azure Artifacts only.
##[error]The nuget command failed with exit code(1) and error(NU1101: Unable to find package BotUtility. No packages exist with this id in source(s): NuGetOrg
Is it possible for the Build Pipeline to reach this package inside Azure Artifacts and if so, how can i implement this? Can i add the package feed source in the Pipeline config?
There is a more detailed screenshot of the error location.
Here is my current version of the Build pipeline.
Well you can add your nuget feed to the nuget task;
Another way is to define a nuget.config in your project, and add your package there:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- NuGet packages are now stored globally, see: https://stackoverflow.com/a/35809007/4122889 -->
<!-- see: https://stackoverflow.com/a/53451805/4122889 -->
<config>
<add key="globalPackagesFolder" value=".\Packages" />
<add key="repositoryPath" value=".\Packages" />
</config>
<!-- Setup for local packages, not in a nuget source -->
<packageSources>
<add key="MY_FEED" value="https://pkgs.dev.azure.com/org/project/_packaging/MY_FEED/nuget/v3/index.json" />
<!--<add key="LocalPackages" value="./LocalPackages" />-->
</packageSources>
<activePackageSource>
<!-- this tells that all of them are active -->
<!--<add key="All" value="(Aggregate source)" />-->
</activePackageSource>
</configuration>
I am creating a NuGet package that adds or modifies several xml files. I want the Nuget package to add and then modify the xml files, so the user does not have to do anything to get the file added if it does not exist. I need to modify the xml file to customize it for the specific application.
The code I am using in the .nuspec file is:
<files>
<file src="web.config.*.xdt" target="content"/>
<file src="App_Data\*.xml" target="content\App_Data"/>
<file src="App_Data\*.xml.*.xdt" target="content\App_Data"/>
<file src="favicon.ico" target="content\favicon.ico"/>
</files>
The code with will add the file if they do not exist, or modify them if they do, but it won't add them and then modify them.
Each file I am trying to add then modify as a .install.xml.xdt file associated with it.
I am using a custom RoleManager. The xml file contents are:
<?xml version="1.0" encoding="utf-8" ?>
<roleManager />
The xml.install file contains:
<?xml version="1.0" encoding="utf-8" ?>
<roleManager xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
xdt:Transform = "SetAttributes(defaultProvider,enabled,cacheRolesInCookie,cookieProtection)"
defaultProvider="RoleProvider"
enabled="true"
cacheRolesInCookie="true"
cookieProtection="All" >
<providers xdt:Transform="Insert" >
<clear />
<add name="RoleProvider" type="Library.RoleProvider" applicationName="$RootNamespace$" />
</providers>
</roleManager>
Is there any way to accomplish what I want to do?
I have a tentative approach to the problem: Create a dependent solution to add the files.
The dependent solution has the following nuspec section:
<files>
<file src="App_Data\*.xml" target="content\App_Data"/>
</files>
This nuget package is then listed as a dependency in the main library as such:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Timothy R Dooling</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<file src="App_Data\*.xml" target="content\App_Data"/>
<dependencies>
<dependency id="LibraryCore" version="1.0.0" />
</dependencies>
</metadata>
<files>
<file src="web.config.*.xdt" target="content"/>
<file src="App_Data\*.xml.*.xdt" target="content\App_Data"/>
<file src="favicon.ico" target="content\favicon.ico"/>
</files>
</package>
The only hassle with this approach is that you have to uninstall the dependency or hand-delete the added files in order to completely undo the changes made to the application.
It would be preferable since such changes could involve more than one dependencies if the nuspec in the main package would know enough to uninstall the dependent package.
Anyone know how to get it to do that?
I recently added grial nuget packages to a xamarin solution.
It works fine locally but the build fails on mobile.azure.com.
I have used the nuget command line to add the new package source, including the credentials as a username / encrypted password.
It still breaks the build though, but this time with the error
"Data unprotection failed."
Has anyone come across this before, and do you have any possible solution?
thanks
You need to consider adding a nuget.config file. Below is an example that we used to include our Proget Feed.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="true" />
<add key="automatic" value="true" />
</packageRestore>
<packageSources>
<add key="NRTH Proget" value="http://proget.nrth.com/nuget/nuget" />
</packageSources>
</configuration>
Just drop this file in the same folder as your solution (.sln) file.
I have a class library package that needs to merge the following to the existing web/app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MyCompany.MyLibrary" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<MyCompany.MyLibrary.Settings>
<setting name="Environment" serializeAs="String">
<value></value>
</setting>
</MyCompany.MyLibrary.Settings>
</applicationSettings>
</configuration>
I did this using .transform files and it installs fine.
The user (using NuGet 2.8.3 and VS 2012) is able to easily edit the value in "Environment" to properly configure the library.
However, when I release the next version, the user runs into a problem when they use NuGet to update their solution.
The update clears out their existing "Environment" value in the user's config files.
I tried using an .install.xdt file and do:
<setting name="Environment" serializeAs="String" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)">
That didn't work either. Is there a way to tell NuGet to ignore the value under "Environment" if it's already there so it doesn't clear out existing values?
I don't want to apply that ignore logic to all of MyCompany.MyLibrary.Settings in case a future update adds or removes a new setting.
I'm using nuget integration with msbuild (visual studio 2012) to automatically restore broken packages. Below you can see my .nuget/nuget.config file for solution:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<config>
<add key="repositoryPath" value="..\..\Lib\NuGet\Packages" />
</config>
</configuration>
My packages directory moved outside from solution. This works fine during build, but Package Manager Console still using $(SolutionDir)\packages to install (and restore) packages.
It is possible to change packages directory for "Package Manager Console"?
nuget.config
You got the first part:
<config>
<add key="repositoryPath" value="..\MySuperCoolPackages" />
</config>
But you have to tell the command line about the nuget.config file explicitly.
C:\SomeFolder\NuGet.exe install "C:\MySolution\.nuget\packages.config" -ConfigFile "C:\MySolution\.nuget\nuget.config"
When you create nuget.config with repositoryPath you need to restart VS for it to be reread and console to be aware of it.
Edit: #DmitryBykadorov weird, may be your nuget is out of date? There was an early problem where due to config being in .nuget subfolder and not in .csproj's current>parent>parent>etc path it wouldn't see it and required one nuget.config with restore info and one (typically next to .sln or .csproj itself) with repositoryPath, but my VS2012 with whatever latest nuget it comes with works fine with config below. May be your global nuget config somehow affects it, or your solution needs hard clean/rebuild?
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<config>
<add key="repositoryPath" value="..\..\lib" />
</config>
</configuration>