"Add postsharp to this project" not working - postsharp

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?

Related

What's the current impl. of NuGet stuff in .csproj?

I have a few solutions that started out in VS2008 or VS2010 or something like that. They contain some stuff that I think relate to NuGet package restore and including certain MS NuGet packages in the build process.
But this looks different in different projects, while I see no reason for any differences, and a new VS2017 project contains yet another different version.
So, what could I safely do to get my old projects up to date in this regard - what should it look like now, in VS2017?
Both old solutions contain a solution-level subfolder ".nuget" with three files: NuGet.Config, NuGet.exe and NuGet.targets.
The old .csproj files contain these "versions" of NuGet stuff:
Proj1:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
Proj2 (additional conditions):
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
Proj3 (doesn't import nuget.targets):
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
A new VS2017 web application project (doesn't import nuget.targets or Microsoft.Bcl.Build.1.0.21, different <Error Condition.../> tags):
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
I would like to have the same setup for all these old projects (unless there would be specific reasons to differ), and I want the setup to be up to date with the tools and environment as per VS2017.
I have automatic package restore enabled and want to keep it that way.
Note: All four projects seem to build and run successfully. Proj2 and Proj3 are unit test projects. Proj1 is really two projects that are identical in this respect.
What's the current impl. of NuGet stuff in .csproj?
To resolve this question, you can follow below steps:
Close Visual Studio to avoid file potential file locks and conflicts.
If using TFS: Remove nuget.exe and nuget.targets from the solution's .nuget folder and remove those files from the solution workspace. Retain nuget.config with the disableSourceControlIntegration setting as explained in Omitting packages with Team Foundation Version Control.
If not using TFS: Remove the .nuget folder from the solution and the solution workspace.
Edit each project file in the solution, remove the <RestorePackages> element, and remove any references to the nuget.targets file.
<RestorePackages>true</RestorePackages>
And
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
Note: Retain <Import Project="..\packages\Microsoft.Bcl.Build...
For some details, please refer to:
Nuget: Switching from "Enable Package Restore" to "Automatic Package Restore".

How to run PostShard samples from 2.1 to 4.1?

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.

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>

Deploying MVC4: System.IO.FileNotFoundException [duplicate]

I have a small web application. Which was working fine until I added two genericHandler in my application.
I have made the following changes for the http handler
<system.web>
<authentication mode="Forms" >
<forms protection="All" timeout="720" defaultUrl="Default.aspx" loginUrl="Login.aspx" >
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<!--Code Log Handler-->
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
<add verb="*" type="InfoDomeNewUI.Handler.SendOWA" path="SendOWA.ashx" />
<add verb="*" type="InfoDomeNewUI.Handler.SendSOS" path="SendSOS.ashx" />
</httpHandlers>
<customErrors mode="Off">
<error statusCode="404" redirect="Templates/PageNotFound.html" />
</customErrors>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<!--Code Log Handler-->
<add name="LogHandler1" path="SendOWA.ashx" verb="*" type="InfoDomeNewUI.Handler.SendOWA"/>
<!-- SMS SENDER-->
<add name="SendSOS" path="SendSOS.ashx" verb="*" type="InfoDomeNewUI.Handler.SendSOS"/>
</handlers>
</system.webServer>
Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I am using asp.net4.0 and C#. I am not using MVC
On local host it is working fine.
But when I am hosting the published code it is giving me the above error.
Stack Trace:-
[FileNotFoundException: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Web.Http.WebHost.SuppressFormsAuthRedirectModule.Register() +0
[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +11708830
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +465
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLeve
[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11697760
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4866485
It appears that Microsoft.Web.Infrastructure.dll is not being installed in the GAC, even if .net (4.0 or 4.5 or other) are installed successfully on Windows Server. On localhost (typically Windows client), it seems like it is being in the GAC when the tools/platform (Visual Studio etc.) are installed.
As one possible fix, please try the following:
Run the following command in the Package Manager Console. (If you are using Visual Studio, this can be reached via menu options "Tools --> Library Package Manager --> Package Manager Console:)
PM> Install-Package Microsoft.Web.Infrastructure
You will see the following messages if it is successfully installed.
Successfully installed 'Microsoft.Web.Infrastructure 1.0.0.0'.
Successfully added 'Microsoft.Web.Infrastructure 1.0.0.0' to Web.
You will notice that Microsoft.Web.Infrastructure.dll has now been added as a Reference (can be seen in the references folder of your project in in Solution Explorer)
If you look at the properties of this reference you will notice that "Copy Local" has been set to "True" by default.
Now when you "Publish " your project, Microsoft.Web.Infrastructure.dll will be deployed.
I installed MVC4 via WPI and it helped me.
I had the same problem. When I tried the accepted answer (rockyb), I got the message that the package was already installed and assigned to my project. When I checked the references list, it was NOT referenced, however.
The Microsoft.Web.Infrastructure was installed in my solution's packages folder. Instead of using NuGet to add the package, I just used the Add Reference option. On the left side of the pop-up window, I chose Browse, and then pressed the Browse button on the bottom of the window. I navigated to the packages folder under the folder that my solution was in, then drilled down to the ...\mysolution\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40 and clicked on the Microsoft.Web.Infrastructure.dll. After clicking OK, the package showed up in my References list. I used the Web Deploy Package option to deploy my website and everything worked.
Why not copy Microsoft.Web.Infrastructure.dll file manually to the server BIN folder. This works for. My project is VS2010 Website.
This file can be located:
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40
Just copy and paste it in the BIN folder.
You probably need to include this in the web.config if you don't have it already
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
Reference: http://thedeveloperblog.com/
I found the problem. Instead of adding a class (.cs) file by mistake I had added a Web API Controller class which added a configuration file in my solution. And that configuration file was looking for the mentioned DLL (Microsoft.Web.Infrastructure 1.0.0.0).
It worked when I removed that file, cleaned the application and then published.
After installing Microsoft.Web.Infrastructure through Nuget-Package Manager
PM> Install-Package Microsoft.Web.Infrastructure
Copy the Microsoft.Web.Infrastructure.dll manually from the Nuget-Package folder on your web application and then paste it in your bin folder of your web application deployed on the web server.
packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
It worked for me.
Update-Package -reinstall Microsoft.Web.Infrastructure didn't work for me, as I kept receiving errors that it was already installed.
I had to navigate to the Microsoft.Web.Infrastructure.1.0.0.0 folder in the packages folder and manually delete that folder.
After doing this, running Install-Package Microsoft.Web.Infrastructure installed it.
Note: CopyLocal was automatically set to true.
Sometimes needs to delete the package with force then reinstall it
its works for me.
try delete package
Uninstall-Package Microsoft.Web.Infrastructure -force
then install again
Install-Package Microsoft.Web.Infrastructure
I had the same problem and the "Microsoft.Web.Infrastructure.dll" appeared to be missing. I have tried few advises and installed MVC`s etc. and nothing helped. The solution was to install "Web Services Enhancements (WSE) 1.0 SP1 for Microsoft .NET" which includes Microsoft.Web.Infrastructure.dll.
Available at: http://www.microsoft.com/en-gb/download/details.aspx?id=4065
I had the same problem. I tried installing Visual Studio 2010 SP1 but it didn't worked.
Finally I get Microsoft.Web.Infrastructure.dll from the colleague. You can find the dll into your friends PC where the project is perfectly working. Try to search dll into Temp/Temporary ASP.NET Files. Go to Temp using %temp% into run window.
After getting dll into your pc, just add reference to your project and it will work.
Republishing the site fixed the issue for me.
Was facing the same issue and unfortunately nothing here was working. Finally, I came across this link: https://blogs.msdn.microsoft.com/jjameson/2009/11/18/the-copy-local-bug-in-visual-studio/
Turns out the solution is sort of dumb: set copy-local for the microsoft.web.infrastructure dll to False, then set it back to True.
By the way, I think what is happening is that there are two versions of the microsoft.web.infrastructure dll, one that is pre-installed in the GAC, and another one that is now a nuget package. I think one is masking the other, hence causing issues. In my particular case, on my build server, I need it to be copied over to a folder (this folder is then zipped and sent off to deployment). I guess the system had a copy locally and just thought "nah, it'll be fine"
I have a files only website. Added MVC 5 to webforms application (targeting net45). I had to modify the packages.config
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45"
to
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" developmentDependency="true"
in order for it to startup on local box in debug mode (previously had the top described error). Running VS 2017 on Windows 7...opened through File > Open > Web Site > File (chose root directory outside of IIS).
I had the same problem after upgrading a bunch of NuGet packages.
I have tried all kinds of deleting, cleaning, resintalling described here and beyong to no avail. The references did not have Microsoft.Web.Infrastructure despite the NuGet manager showed it was installed.
The problem was solved by replacing:
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
with
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
in packages.config. The culprit is apparently "net45".
Visual Studio 2022 .net.4.8
I just run this and is solved
you can install this dll using nuget package manager
PM> Install-Package Microsoft.Web.Infrastructure -Version 1.0.0

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.