How do you add an xml file to the App_Data folder of a web site and then modify it with NuGet - nuget-package

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?

Related

Missing NetStatandard 2 after install my nuget package

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

Grial nuget package breaks build on mobile.azure.com

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.

NuGet release.config.install.xdt Retain Transforms

I'm creating a NuGet package that contains a web.release.config.install.xdt file. But, every transform in the file is processed by NuGet.
Here's the contents of the web.release.config.install.xdt file:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!-- I only want this xdt:Transform to be handled by NuGet -->
<solr xdt:Transform="Insert">
<!-- the below xdt:Transform attributes are also processed by NuGet -->
<server id="location" url="http://192.168.1.100:8983/solr/geo" xdt:Transform="SetAttributes" xdt:Locator="Match(id)" />
</solr>
</configuration>
Any suggestions on the proper way to escape the nested transforms so they are retained for the web.release.config file?

It is possible to change packages installation directory for Package Manager Console?

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>

Sharepoint 2010 WSP Deployment problem. Can’t deploy new files

We have found a problem with our deployment to a production server that runs Sharepoint 2010 Publishing Site Collection.
We are deploying WSP packaged from Visual Studio to Sharepoint Management Shell (Uninstall, reinstall solution). It has worked like a charm in the past. We added a custom masterpage, css files, images and later we successfully added custom page layouts.
I also have SP running locally on my computer and everything works fine with no problem adding new files via deploying Feature. I can add them neatly into a document library or even create new folders from the Elements file.
However the problem arise when I deploy my WSP to the production server. I want to add a few JS files and a XSL file to the Style Library but the files won't get added to the document library. The deployment process goes smooth though with no errors and when I check my feature in Sharepoint Hive, the new files are there on the physical drive! However they won't get added to the virtual Document Library.
I can update existing files like the masterpage and CSS files so the feature that is deployed is working.
My guess is that either it has to do with permission problems or some bug in my code. But I did exactly as we have done before when deploying.
This is how my Elements.xml file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="ALayout" Url="_catalogs/masterpage" RootWebOnly="true" >
<File Path="ALayout\_a_intra.master" Url="_a_intra.master" Type="GhostableInLibrary" />
</Module>
<Module Name="ALayoutStyles" Url="Style Library" RootWebOnly="true" >
<File Path="ALayout\styles\z_aintra_core.css" Url="z_aintra_core.css" />
<File Path="ALayout\styles\aintra_std.css" Url="aintra_std.css" />
</Module>
<Module Name="ALayoutStyleImages" Url="Style Library/img" RootWebOnly="true" >
<File Path="ALayout\styles\img\a-logobig.png" Url="a-logobig.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\bg.png" Url="bg.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\divider.png" Url="divider.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\nav-bg-hovered.png" Url="nav-bg-hovered.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\nav-bg-radius-left.png" Url="nav-bg-radius-left.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\nav-bg-radius-right.png" Url="nav-bg-radius-right.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\nav-bg-selected.png" Url="nav-bg-selected.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\nav-bg.png" Url="nav-bg.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\nav-divider.png" Url="nav-divider.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\top_bg.png" Url="top_bg.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\user-account-radius-left.png" Url="user-account-radius-left.png" Type="GhostableInLibrary" />
<File Path="ALayout\styles\img\user-account-radius-right.png" Url="user-account-radius-right.png" Type="GhostableInLibrary" />
</Module>
<Module Name="ALayoutScript" Url="Style Library/js" RootWebOnly="true" >
<File Path="ALayout\js\script.js" Url="script.js" Type="GhostableInLibrary" />
<File Path="ALayout\js\plugins.js" Url="plugins.js" Type="GhostableInLibrary" />
</Module>
<Module Name="ALayoutScriptLibs" Url="Style Library/js/libs" RootWebOnly="true" >
<File Path="ALayout\js\libs\jquery-1.4.2.min.js" Url="jquery-1.4.2.min.js" Type="GhostableInLibrary" />
</Module>
</Elements>
The last two modules (for Javascript) is the ones I can't deploy to the document library. I tried different document libraries but it still doesn't work on production server, just locally. And I can't deploy to Sharepoint Hive via Feature.
Anyone can think of something I missed?
Wow, the solution was simple. I deactivated the feature in Sharepoint administration, and reactivated it and the new files got deployed.
WHY this happened, I don't know. If I version my feature instead of uninstall->add it might get fixed?
Why is the behavior different on the production farm vs local? etc.
There are few points I want yo bring to your notice. Just check if you are already following them...
I hope you have "js" folder in your VS solution (under ALayout module).
Add IgnoreIfAlreadyExists="FALSE" attribute to the node
File Path="ALayout\js\libs\jquery-1.4.2.min.js" Url="jquery-1.4.2.min.js" Type="GhostableInLibrary" IgnoreIfAlreadyExists="FALSE"/
Use ULSViewer to see any errors while deploying on production...

Resources