NuGet DependentUpon files - wpf

Let's say I have a WPF Control that I want to deploy as source code transformation via NuGet.
The control has 2 files associated with it: UserControl.xaml.cs and UserControl.xaml.
When I deploy it via NuGet I get the files in the target project, but they don't have the hierarchy structure in the solution explorer. This is due to the fact that NuGet does not know how to add the DependentUpon property in the .csproj file.
Is there a workaround? Is this feature in the roadmap of NuGet?
Thanks
Tal

The answer is Powershell, specifically the Install.ps1 file that will execute automatically upon install if placed within a /tools folder in your NuGet package. Here's code that should do the trick:
param($installPath, $toolsPath, $package, $project)
$buildProject = #([Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName))[0]
$file = $buildProject.Xml.Items | Where Include -eq "UserControl.xaml.cs"
$propertyToEdit = $file.Metadata | Where Name -eq "DependentUpon"
if (!$propertyToEdit)
{
$file.AddMetaData("DependentUpon", "UserControl.xaml") | Out-Null
}
$project.Save()
You may not see the change immediately in the Visual Studio interface, but if you unload/reload or close/open the project, you'll see it.

Related

Portable Extensible Metadata (PEM) and Visual Studio 2013

In a previous project, I used the "Portable Extensible Metadata" tool. It was helpful in that it allowed me to store the label text and the tooltip text in the EMDX and show them in the WPF-UI. The feature to store the valuation is also nice, but I donĀ“t need it urgently.
Now I use VS2013 and I can't install PEM anymore. How can I find a updated version of this extension? Where can I find the source code so that I can compile a custom-version for my project?
I am working on a project which involves the same setup, that is, PEM using VS2013.
Earlier when I was using VS2010, it gave me the option of product VS2010 only for this extension(pem.VSIX) to be installed to. Even now, when I have VS2013 installed on my machine, it gives the same option of installing this extension to VS2010 and not VS2013, as I tried uninstalling and re-installing this extension. Please refer to the screenshot.
Just to mention, the extension can be installed simply be double-clicking on it.
The following is what I did and it worked for me.
Look for PEM_VSIX2012 on the internet or just make changes to the VSIX for VS2010 that you have at your disposal. Open this archive using 7-Zip tool and you will find a bunch of files. Look for the file "extension.vsixmanifest" and edit it in the 7-Zip archive window itself. There's a tag as mentioned below along with the tags for VisualStudio versions.
You just need to add the VisualStudio Verion to it that you are using.
<SupportedProducts>
<VisualStudio Version="10.0">
<Edition>VST_All</Edition>
<Edition>Pro</Edition>
</VisualStudio>
<VisualStudio Version="11.0">
<Edition>VST_All</Edition>
<Edition>Pro</Edition>
</VisualStudio>
<VisualStudio Version="12.0">
<Edition>VST_All</Edition>
<Edition>Pro</Edition>
</VisualStudio>
</SupportedProducts>
Like I added the following to the "extension.vsixmanifest" file.
</VisualStudio>
<VisualStudio Version="12.0">
<Edition>VST_All</Edition>
<Edition>Pro</Edition>
</VisualStudio>
Next, as I stated earlier, you should be able to install the extension simply by double-clicking on it. But if that doesn't works out, try this:
Run 'Developer Command Prompt for VS2013' as Administrator
and use the VSIXInstaller tool to install the extension by running the following command:
VSIXInstaller "path_to_VSIX_file"
Now pack the contents back into a zip-archive. Make sure the archive have the VSIX extension.
And as shown in the image above, alongwith VS2010, VS2013 would also be shown for installing this extension to.
Hope this helps.

Create Nuget package for Dacpac and Powershell script

How do I create a Nuget package in Visual Studio 2013 that includes a dacpac and a Powershell script? Would I have the two files in the same location then call nuget pack {folder name}? The Powershell script essentially deploys the dacpac to Octopus Deploy. I have the pieces, but I'm not sure how to put them together!
Are your Powershell script and dacpac in the Visual Studio project? If not, you may not need to include VS in the process.
You can use either OctoPack or the NuGet command line tool.
Either way, you will need to create a nuspec file before you can run the pack command. You can create one manually following the format in the docs or you can use the nuget spec command to create one. Once you have the nuspec file, you can use nuget pack to create the nupkg file.
If the files have to be in a Visual Studio project, the steps are pretty much the same, but you might have to do a little extra work to get the deploy script in the correct spot for Octopus to call it.
Edit: This was posted recently http://swoogan.blogspot.ca/2015/04/deploying-dacpacs-with-octopus-deploy.html

No Silverlight project specified for Silverlight output

I have a very standard silverlight app running under an ASP.NET host. On all dev machines it compiles fine, but on our CI serve, we get this error:
No Silverlight project specified for Silverlight output
But if I log into CI and compile manually with VS2010 it works fine! This is Silverlight 4, .NET 4.0
As I just spent 2 days trying to figure out why this was happening in a Silverlight project I work on, I figured I'd post it here.
In my case, the problem was caused because one of the <ProjectReference> in website's .csproj had a project GUID which didn't match the actual GUID of the project (due to a code reorganization which had occured earlier).
This had nothing to do with the silverlight application or any of its settings. I have no idea why, but somehow this bad reference causes the "CopyFilesToFolders" MSBuild task to get a the same files listed multiple times in the "SourceFiles" list. This causes the first set of copys to succeed followed by a set of "No Silverlight project specified" errors.
Simply removing the bad project reference and re-adding it fixed the GUID and solved the build issue.
A very very bad error message indeed.
Thanks to MerickOWA for posting here, I am sure it saved me hours with the same problem.
I have created a PowerShell script to find the mismatched GUIDs for all projects in a solution. It may save someone else even more hours.
To run it, copy the code below into a text file in the same folder as your solution, rename to .ps1, start up the Powershell console, navigate to the folder containing you solution, then run the script. It will list mis-matched project references, if any.
To fix, open the solution in Visual Studio then remove and re-add the mismatched Project Reference(s).
function validateSolution([string]$slnFileName) {
"Validating solution: " + $slnFileName
# Extract all the c# projects from the solution file
$solutionProjects =
Get-Content $slnFileName | Select-String 'Project\(' | ForEach-Object {
$projectParts = $_ -Split '[,=]' ;
New-Object PSObject -Property #{
Kind = $projectParts[0].Replace('Project("', '').Replace('") ','');
Name = $projectParts[1].Trim('" ');
File = $projectParts[2].Trim('" ');
Guid = $projectParts[3].Trim('" ');
};
} | Where-Object { $_.Kind -eq "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" } # Kind = C# project
# Output list of C# projects to console
# $solutionProjects
# Create HashTable keyed on project GUID
$solutionProjectGuids = #{}
foreach ($project in $solutionProjects) {
$solutionProjectGuids.Add($project.Guid, $project)
}
# Loop through each c# project in the solution
foreach ($project in $solutionProjects) {
[xml]$projectXml = Get-Content $project.File
$projectReferences = $projectXml.Project.ItemGroup | Where-Object { $_.ProjectReference -ne $null }
# Loop through each ProjectReference
foreach($reference in $projectReferences.ChildNodes | Where-Object { $_.Project -ne $null } ) {
# Check the project reference GUID exists in hash table of project GUIDS; if not write error
if (!$solutionProjectGuids.ContainsKey($reference.Project)) {
""
"Bad ProjectReference: Project GUID not found in solution "
"Solution: " + $slnFileName
"Project: " + $project.File
"Reference: " + $reference.Name
"Bad GUID: " + $reference.Project
}
}
}
"Completed solution: " + $slnFileName
}
foreach ($solutionFile in ls *.sln) {
validateSolution $solutionFile
}
If you take a look at the log file that is generated by your build server, you will probably see something like this...
CopySilverlightApplications:
Copying Silverlight applications
Copying <Path>.xap to <Path>.xap
MSBUILD : error : Copying file <Path>.xap failed. No Silverlight project specified for Silverlight output <Path>.xap. [<Path>.csproj]
CopySilverlightApplications is a target that is defined in the following file.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets
It includes this condition which explains why you are not having the problem when building with Visual Studio.
Condition="'$(BuildingInsideVisualStudio)' != 'true'"
I have two build definitions where each builds a different configuration. One of the builds was OK (Release) but the other (Nightly) had the problem that you describe. When I looked at the project file for the silverlight application using an XML editor, I saw that although there was a property group with a condition that evaulated to true for Release - there was none for Nightly.
I manually edited the file by taking a copy of the property group for Release and adjusted the condition and the OutputPath to suit the Nightly build. This resolved the issue.
I noticed afterwards that if I navigated to the Properties page for the Silverlight project in Visual Studio and swapped to the Nightly configuration using the dropdown in the toolbar, that a new PropertyGroup element was automatically generated for that configuration. This would probably also resolve the issue.
I had the same problem. The project built just fine in Debug and Release configuration but I got "No Silverlight project specified for Silverlight output" in the web-project. I also noticed that it was trying to copy the .xap-files from ./bin/Release/ instead of ./bin/Production/.
After removing all Silverlight Applications (tab in project Properties) from the web-project and adding the ClientBin folder as the output path (suggested here) I got a better error message. The problem was that some projects referenced by the web-project were missing the selected configuration. After adding the configuration I could add the Silverlight Applications to the web project again and return the Output path to bin/$(Configuration)/ and still build the solution.
I seemed to be getting duplicate xap file names being generated within the CopySilverlightApplications task which were causing this error. I was able to resolve this issue by making the modification below to the following file. Note the introduction of a new ItemGroup and the reference to it from the SourceFiles attribute in the CopyFilesToFolders Task.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets
<ItemGroup>
<_UniqueSilverlightXapFiles Include="%(_SilverlightXapFiles.FullPath)" />
</ItemGroup>
<!--Copy the outputs to the target folder-->
<CopyFilesToFolders SourceFiles="#(_UniqueSilverlightXapFiles)"
SilverlightApplications="#(_SilverlightApplications)"
ConfigName="$(Configuration)"
Condition="'#(_SilverlightXapFiles)' != ''">
<Output TaskParameter="DestinationFiles" ItemName="_WebApplicationSilverlightXapFiles" />
</CopyFilesToFolders>
To further confuse the matter, I added 2 new projects to our existing solution (a new library and it's associated test project) and the CI build failed with the no silverlight project specified for silverlight output error, which was succeeding 2 days prior. The 2 new projects didn't have the configuration being used by the other projects.
Adding the missing configuration to the 2 new projects via the Solution Configuration Manager fixed it.
Why this would affect the Silverlight projects, which have no relation to these 2 new projects, I have no idea.
I had the same problem. I was making build script, running msbuild on solution.
I was building solution in "Test" configuration, but web project that referenced Silverlight projects kept looking in target bin\Release folder for binaries.
I tried re-adding Silverlight projects, problem was still there.
It turned out problem was to specify Platform in msbuild arguments.
Solution configuration "Test|AnyCPU" and "Test|MixedPlatform" is no same. You will find that both Configuration and Platform has to be equal to same pair defined in project file. I don't know what Platform was msbuild taking by default, but I know it jumped to Release folder instead.
Anyway, I added /p:Platform="Any CPU" to msbuild arguments.
After carefully reviewing the configuration that was being built for CI, I found that one of the projects being referenced by my web project was set up to build with a wrong configuration. My CI build was set up to build for Staging (Any CPU) and one of my .projects that was being referenced by the Web project was set up to build using Release configuration. Once I updated the Configuration to be Staging, the CI build completed successfully

Finding third party licenses with Nuget

I'm a bit of a NuGet newbie and have come from the Maven world.
Recently I've been tasked with updating the third party licence information for our projects. Working with the Maven projects I've been able to use the license:download-licenses plugin to get the licence information.
What I'm wondering is if there is a way to get this information using Nuget? Preferably by using the command line interface so I can automate it at a CI build level. To remove it from the large manual pre build step.
EDIT:
Since I wasn't able to find any utilities to do this I put together the LegSec command line utility.
As far as I am aware there is nothing currently available to get the license information directly from the command line as part of a CI build. You would need to create an application to open the .nupkg zip file, extract the license url from the .nuspec file and download the license from this url.
Alternatively you could use the package manager console window inside Visual Studio and with a bit of PowerShell download the license files.
A simple example that gets the license file for all packages in a project is shown below. This would need to be extended to get all the projects in the solution which you should be able to do with the Get-Project cmdlet. This would still require someone to run the script to download the licenses.
$wc = New-Object System.Net.WebClient
Get-Package -ProjectName YourProject | ForEach-Object {
$wc.DownloadFile($_.LicenseUrl, 'd:\licenses\' + $_.Id + ".html")
}
I managed to get the licence information with the following command:
#(#(Get-Project -All | ForEach-Object {
Get-Package -ProjectName $.ProjectName
}) | Select Id -Unique ) | ForEach-Object {
$pkg = $_
$pkgId = $_.Id
if ($pkgId -notlike 'microsoft*') {
$url = Open-PackagePage $pkgId -License -WhatIf -PassThru
Write-Host "$pkgId $url"
}
}

Creating Silverlight 3 applications with F#

Is there an easy way to create Silverlight 3 applications with F# (October CTP)?
I have seen the F# for Silverlight, but that only works with the May CTP.
I am using Visual Studio Integrated Shell 2008.
It is possible to use the May CTP templates with the October CTP version of F#
Create your new project, then unload it and edit the hint path for the FSharp.Core.dll to point to the October CTP,
<HintPath>$(ProgramFiles)\fsharp-1.9.7.8\Silverlight\2.0\bin\FSharp.Core.dll</HintPath>
then reload the project and build.
You do have to package the .xap file manually by e.g. using the chiron tool (or just zipping and renaming)
The AppManifest.xaml file looks like
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RuntimeVersion="3.0.40818.0"
EntryPointAssembly="astroclock-fs"
EntryPointType="astroclock.fs.MyApp">
<Deployment.Parts>
<AssemblyPart x:Name="astroclock-fs" Source="astroclock-fs.dll" />
<AssemblyPart x:Name="FSharp.Core" Source="FSharp.Core.dll" />
</Deployment.Parts>
</Deployment>
where you fill in your own assembly name and entrypoint instead of mine
Create a folder in $(ProjectDir) to hold all the files to be packaged and copy C:\Program Files\FSharp-1.9.7.8\Silverlight\2.0\bin\FSharp.Core.dll into it, along with the AppManifest.xaml above
Create an empty file null.py in the folder to keep chiron quiet if you are using that tool
Add the following post-build steps
cd $(ProjectDir)
copy /y $(OutDir)$(TargetFileName) [your directory with all the output]
"C:\Program Files\IronPython 2.0\Silverlight\bin\chiron.exe" /d:[your directory with all the output] /z:app.xap
Create a test page to load app.xap
Build project
Load page in browser and enjoy
ADDED
You can make a permanent fix for the hint path needed to find FSharp.Core.dll by editing the template in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplatesCache\FSharp\Silverlight\SilverlightLibrary3.zip\SilverlightLibrary.fsproj (and probably the version of the file in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\FSharp\Silverlight\SilverlightLibrary3.zip just to be certain).
And a working proof of concept (source and everything bundled into the xap) here.
Looks like I got to wait for VS 2010.

Resources