Copy the nuget content folder to project output folder - nuget-package

I have created a nuget package with this structure:
NugetName/lib/net/*.dll
NugetName/contentFiles/A/*.dll
NugetName/contentFiles/B/*.dll
> <?xml version="1.0" encoding="utf-8"?> <package
> xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
> <metadata>
> <id>..</id>
> <version>1.0.0.22</version>
> <title>...</title>
> <authors>...</authors>
> <owners>..</owners>
> <requireLicenseAcceptance>false</requireLicenseAcceptance>
> <description>...</description>
> <contentFiles>
> <files include="contentFiles\A" buildAction="content" copyToOutput="true" flatten="true" />
> <files include="contentFiles\B" buildAction="content" copyToOutput="true" flatten="true" />
> </contentFiles>
> </metadata>
> <files>
> <file src="Build\Debug\*.dll" target="lib\net\" />
> <file src="Build\Debug\A\*.dll" target="contentFiles\A" />
> <file src="Build\Debug\B\*.dll" target="contentFiles\B" />
> </files>
> </package>
And now, I need to copy the folders A and B into the project's output folder, but it does not do that!
After installing the nuget package, only the NugetName/lib/net/*.dll files are copied, but A and B are not!

After testing the different ways I came up with this solution.
First, I sent the dll files into the Build folder instead of the content folder.
<files>
<file src="Build\Debug\*.*" target="lib\net\" />
<file src="Build\Debug\A\*.dll" target="build\A" />
<file src="Build\Debug\B\*.dll" target="build\B" />
<file src="MyTargetFile.targets" target="build\MyTargetFile.targets" />
</files>
Then, I created a target file in the Build folder.
This is the new structure of my nuget package:
•Build
•A
•*.dll
•B
•*.dll
•MyTargetFile.target
•lib
• net
•*.dll
In the target file I defined how to copy the folder by MsBuild:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)**\*.dll" />
<None Include="#(NativeLibs)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Finally I created the new nuget package and installed it, and when I built the project, folders A and B are copied into the output folder.

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

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

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?

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>

Minifying JS/CSS for Web Deploy

I'm trying to Minify Javascript and CSS using AjaxMin when I deploy using a Web Deploy Publish Profile. Here is what I have in the project file:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\AjaxMin.tasks" />
<PropertyGroup>
<ResGenDependsOn>
MinifyJavascriptAndCss;
$(ResGenDependsOn);
</ResGenDependsOn>
</PropertyGroup>
<Target Name="MinifyJavascriptAndCss"
Condition=" '$(ConfigurationName)'=='Release' ">
<ItemGroup>
<JS Include="$(_PackageTempDir)\**\*.js"
Exclude="$(_PackageTempDir)\**\*.min.js;Scripts\*.js" />
</ItemGroup>
<ItemGroup>
<CSS
Include="$(_PackageTempDir)\**\*.css"
Exclude="$(_PackageTempDir)\**\*.min.css" />
</ItemGroup>
<Message Text="Compressing JavaScript and CSS files into $(_PackageTempDir)"
Importance="high" />
<AjaxMin JsSourceFiles="#(JS)" JsSourceExtensionPattern="\.js$"
JsTargetExtension=".min.js" CssSourceFiles="#(CSS)"
CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" />
</Target>
If I watch the output directory I can see that the files are minified as the min.* files appear, but when the package file is deployed, they are not included.
How do I force the minified files to be included in the publish package?
It worked for me in VS2010, but does nothing with VS2012...
<!-- Use AjaxMinifier from Libs folder in this project -->
<UsingTask TaskName="AjaxMin" AssemblyFile="$(MSBuildProjectLocation)Libs\AjaxMinTask.dll" />
<!-- This target will run after publish web in Release mode -->
<Target Name="MinifyJavaScriptAndCSS" AfterTargets="CopyAllFilesToSingleFolderForPackage" Condition="'$(Configuration)'=='Release'">
<ItemGroup>
<!-- Every .js file (exclude *.min.js and *.vsdoc.js files) -->
<JS Include="$(_PackageTempDir)\**\*.js" Exclude="$(_PackageTempDir)\**\*.min.js;$(_PackageTempDir)\**\*vsdoc.js" />
<!-- Every .css file (exclude *.min.css files) -->
<CSS Include="$(_PackageTempDir)\**\*.css" Exclude="$(_PackageTempDir)\**\*.min.css" />
</ItemGroup>
<!-- Log in output build window -->
<AjaxMin JsKnownGlobalNames="jQuery,$" JsSourceFiles="#(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".js" CssSourceFiles="#(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".css" />
<!-- Log in output build window -->
<Message Text="[pcv] $(MSBuildProjectName) -> Minified: #(JS)" Importance="high" />
<Message Text="[pcv] $(MSBuildProjectName) -> Minified: #(CSS)" Importance="high" />
</Target>
I faced the same problem and successfully resolved it. There is one easy way to do this task.
Set the Build Action of original CSS/JS files to None and set the Build Action of minify files to Content. Now when you build the project then only minified css/java script files will come.
I'm using VS2012, and this worked for me
<!--<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\AjaxMin.targets" />-->
<UsingTask TaskName="AjaxMin" AssemblyFile="$(MSBuildProjectDirectory)\..\packages\AjaxMin.5.14.5506.26202\tools\net40\AjaxMinTask.dll" />
<Target Name="MinifyJsAndCss" AfterTargets="CopyAllFilesToSingleFolderForPackage" >
<ItemGroup>
<JS Include="$(_PackageTempDir)\App_Scripts\**\*.js" Exclude="$(_PackageTempDir)\**\*.min.js" />
<CSS Include="$(_PackageTempDir)\**\*.css" Exclude="$(_PackageTempDir)\**\*.min.css" />
</ItemGroup>
<Message Text="Compressing JavaScript and CSS files...(to edit this feature, unload the project, right click it ->edit -> search for 'AjaxMin' bottom of the xml)" Importance="high" />
<AjaxMin JsSourceFiles="#(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".js" CssSourceFiles="#(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" />
</Target>

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