How to run PostShard samples from 2.1 to 4.1? - postsharp

After download samples from Download - Samples – PostSharp
a "PostSharp Required" dialog was shown asking to install PostSharp 2.1.
I have PostSharp 4.1 installed in my machine, is there a way to run those samples using PostSharp 4.1?

Most samples should be compatible, but are not currently officially supported.
To convert them to the new PostSharp version, you need to edit the csproj file remove the following XML:
<!-- The next section automatically prompts you to install PostSharp if needed. It is not required in normal projects. -->
<UsingTask AssemblyFile="lib\PostSharp.MSBuild.Samples.exe" TaskName="PostSharp.MSBuild.Samples.LaunchPostSharpInstaller" />
<Target Name="PostSharp21Check" Condition="'$(PostSharp21Imported)'==''" >
<LaunchPostSharpInstaller ProjectPath="$(MSBuildProjectFullPath)" Version="2.1" ProjectGuid="$(ProjectGuid)" BuildingProject="$(BuildingProject)" />
<Error Text="To build this project, you must install PostSharp 2.1 on your machine or add it as a NuGet package to this project." />
</Target>
<PropertyGroup >
<ResolveReferencesDependsOn>PostSharp21Check;$(ResolveReferencesDependsOn)</ResolveReferencesDependsOn>
</PropertyGroup>
Additionally, you need to remove all referenced PostSharp assemblies - most likely only PostSharp.dll (either when editing the csproj file or after reopening).
After reopening the project, you should add PostSharp NuGet package, which will install the current version of PostSharp.

Related

How to use Nuget in SharpDevelop?

I am newbie in SharpDevelop and want to download Nuget packages. But I couldn't find any information about this topic on google. How to get Nuget packages in SharpDevelop?
I have taken new nuget.exe from here, put it to c:\test, in cmd -> cd c:\test I then entered nuget to get all info, and tried then nuget install Newtonsoft.Json -version 13.0.1 - getting "nuget argument can not be null or empty" - advice helped - tried ONLY nuget install Newtonsoft.Json - result "nuget unable to find package" - advice helped - I created nuget.config file with such content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
and put it near my new nuget.exe previously loaded...
PROFIT: nuget install Newtonsoft.Json - RETURNED needed nuget package's dlls of Newtonsoft (JSON.NET)...
and through (left-mouse-button in your SharpDevelop project) Referencies - AddReference -> .NET Assembly Browser -> Browse -- you can choose necessary c:\test folder (in my case) and dll version in it and add it to your project...
the oldest version (4.0) is better choice for best compatibility with both OS with NET.Framework 4.0 and OS with NET.Framework later versions as well

"Add postsharp to this project" not working

We had a working PostSharp 6.0.16-rc reference in our .Net 4.7.1 webservice project.
We then tried upgrading to 6.0.34 which adds these two references in .csproj
<PackageReference Include="PostSharp" Version="6.0.34" />
<PackageReference Include="PostSharp.Redist" Version="6.0.34" />
But when we try to enable PostSharp for our webservice project by clicking the "Add PostSharp to this project" button , we are just shown the pop up saying
"Install Nuget package PostSharp 6.0.34 to xxx project"
and when we click next it says
"The operation has successfully completed"
But PostSharp is still not enabled for our project...
We've tried adding the following to our csproj file (but with no effect):
<Import Project="$NugetPackagesPath\PostSharp.6.0.34\tools\PostSharp.targets" Condition="Exists('$NugetPackagesPath\PostSharp.6.0.34\tools\PostSharp.targets')" />
Any ideas on how to force-enable PostSharp?

NuGet Package Restore: Visual Studio Online & POSTSHARP

I installed POSTSHARP as a nuget package and I want Visual Studio Online to automatically restore it.
POSTSHARP must be restored before build though.
I am trying to follow this with no success: link
How can I run scripts / commands in Visual Studio Online BEFORE build?
There are instructions on nuget.org on how to set up a package restore with TFS, including Visual Studio Online: http://docs.nuget.org/docs/reference/package-restore-with-team-build
It mentions that the default Build Process Templates for VSO already implements NuGet Package Restore workflow. So, supposedly, you need to do additional setup only when you customize the templates.
The proposed approach is to create a simple MSBuild project file that will be used to build the solution. You can include all the required targets there (e.g. Build, Rebuild, Clean) that will just invoke MSBuild on your solution file with specifying the corresponding target.
Additionally create a target for package restore - it will invoke NuGet.exe restore MySolution.sln command. The common build targets will depend on this one.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir>$(MSBuildThisFileDirectory)bin</OutDir>
<Configuration>Release</Configuration>
<ProjectProperties>
OutDir=$(OutDir);
Configuration=$(Configuration);
</ProjectProperties>
</PropertyGroup>
<ItemGroup>
<Solution Include="$(MSBuildThisFileDirectory)src\*.sln" />
</ItemGroup>
<Target Name="RestorePackages">
<Exec Command=""$(MSBuildThisFileDirectory)tools\NuGet\NuGet.exe" restore "%(Solution.Identity)"" />
</Target>
<Target Name="Build" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build"
Projects="#(Solution)"
Properties="$(ProjectProperties)" />
</Target>
<!-- other targets... -->
</Project>

Upgrading Entity Framework 4.3.1 to 5.0.0 beta 1 gives binding redirects error

My solution uses Entity Framework 4.3.1. I want to upgrade to 5.0.0 beta-1. The package manager gives the following output:
PM> Install-Package -IncludePrerelease EntityFramework
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=242870. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'EntityFramework 5.0.0-beta1'.
Successfully removed 'EntityFramework 4.3.1' from PROJECTNAME.
Successfully added 'EntityFramework 5.0.0-beta1' to PROJECTNAME.
Failed to generate binding redirects for 'PROJECTNAME'. 'object' does not contain a definition for 'References'
Successfully uninstalled 'EntityFramework 4.3.1'.
It looks like the upgrade completed succesfully, but I wonder how I could have prevented this error.
You should enable automatic binding redirection manually. To do this:
In Visual Studio, in Solution Explorer, right-click the project and choose "Unload Project".
Add the following element to the property group (under the tag) in XML code:
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
The following shows an example project file with the element inserted:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{123334}</ProjectGuid>
...
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
...
</Project>
Right click the project and choose "Reload Project".
Compile your app.
List item
Install EntityFramework.

Packing NuGet projects compiled in release mode?

Is there some way to make a NuGet package using code compiled in release mode? Or is there some reason I should only publish (make available locally, in this case) packages compiled in debug mode?
Every time I call nuget pack from my project directory, where I have the nuspec file below, on code I have only compiled in release mode, it complains about not finding the DLL in the debug folder ("\bin\Debug\SomeProject.dll"). If I compile it in debug mode, those files are there and it packs them up as it should.
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<iconUrl>http://somewhere/project.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
</metadata>
</package>
You can solve it like this:
NuGet.exe pack Foo.csproj -Prop Configuration=Release
(reference)
If you are using a post-build event and you want to create a package whether using Debug or Release configuration you can setup the post-build event commandline like so:
"<path to nuget tools>\NuGet.exe" pack "$(ProjectPath)" -Prop Configuration=$(ConfigurationName)
To have NuGet automatically use Release mode when you run nuget pack, do the following:
Open your .csproj file in a text editor.
Find the following line:
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
In this line, replace Debug with Release.
Save changes.
The answers here are good, but I was having a lot of problems with this for a .NET Standard project. I had a project that was only going to publish Release binaries, but it wasn't respecting my default build output path.
I added this to my CSProj which then enabled me to use the accepted answer here.
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<OutputPath>$(SolutionDir)bin\$(PlatformTarget)\Release</OutputPath>
</PropertyGroup>
Chiming in here.
My build profile would build the DLLs to bin\<arch>\Debug|Release.
I was able to point to my folders by running the nuget command as follows:
Notice how I used the -p option.
PS > nuget pack -p Configuration="x64\Release"
Attempting to build package from ...
...
Found packages.config. Using packages listed as dependencies
...
- Add a dependency group for .NETFramework4.7.2 to the nuspec
Successfully created package...