How do I get Expand-Archive working on Windows 2008R2 using PowerShell 3.0? - .net-4.0

I am in the process of investigating upgrading our PowerShell framework to version 3.0; we currently have many scripts written for 2.0 on Windows 2008R2 servers. I am finding some issues that I can get around easily but I have discovered a bit of fun with the Expand-Archive cmdlet running under PowerShell 3.0 and dotnet 4.0 framework.
Looking here on CodePlex I see the following comment
Upon further investigation the Expand-Archive command is not compatible with
dotnetframework 4.0 when running in 64 bit powershell session. to run this
command in dotnet framework 4.0 ensure that you import the module to:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\Pscx
Then the 32 bit powershell.exe can be invoked and the Expand-Archive command
will run properly. This fix applies to windows 2008 R2 64 bit
I have been able to get the Expand Archive to work locally on a Zip file but when remoting from another PowerShell 3.0 environment I get the following error:
Expand-IHIArchive : Microsoft.PowerShell.Commands.WriteErrorException:
Expand-IHIArchive:: error occurred in Expand-Archive with parameters:
FlattenPaths = False ; LiteralPath =
\Deploys\Packages\POWERSHELL3\CodeReleasePackage.zip ; OutputPath
=\Deploys\Packages\POWERSHELL3 ; PassThru = True ::
Is there a way to get this to work? Or at least figure out from the remote what the problem is?

I got around this by adding the Modules to my environment when they load by putting all the PSCX directory locally to my own copy of PowerShell, basically I load up what PSCX modules I need depending on the PowerShell version. This allows me to control the right version, and make sure the modules are loading properly without worrying about centrally installed modules and this way I can set up my environments easier by having everything packaged up in a structure I like.
This got me past the Expand-Archive issue.

Related

Basic bproject create Failed to create prime the Nuget cache

I am trying to get my first .Net Core solution working.
When I try to create a project in VS 2015, it fails. So back to basics.
Using these directions:
MS .Net Core
I did this.
C:\dev\Tests>mkdir hwapp2
C:\dev\Tests>cd hwapp2
C:\dev\Tests\hwapp2>dotnet -v new
Welcome to .NET Core!
---------------------
Learn more about .NET Core # https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
Telemetry
--------------
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry # https://aka.ms/dotnet-cli-telemetry.
Configuring...
-------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.
Decompressing 100% 1758 ms
Expanding 100% 6072 ms
Failed to create prime the NuGet cache. restore failed with: 1
Telemetry is: Disabled
Created new C# project in C:\dev\Tests\hwapp2.
I am running this in a Command Prompt as an Admin. Same thing happens when I try to create a project in VS 2015. Did try with Firewall turned off by the way.
Environment is
Windows 10 Pro (Build 14393)
VS 2015 with Update 3 (Enterprise)
Dot Net Core Preview 2.0.1 (latest download as of Sept 10th 2016)
You should install the latest .NET Core SDK and remove all previously installed versions.
Try clear nuget cache like in this post. It was helped for me.
Briefly, you need to download nuget command line tool from here.
And then run command:
nuget locals all -clear
This is a known issue.
I had to perform the following steps to fix this issue:
uninstall Microsoft .Net Core SDK 2.0 Preview 1
uninstall Microsoft .Net Core SDK 2.0 Preview 2
This allowed me to execute the command "dotnet run" without the error above.
After running "dotnet run" once I reinstalled Microsoft .Net Core SDK 2.0 Preview 2 again and the error didn't show up anymore (which is what should happen according to this post)
An issue on GitHub describes the situation where dotnet-core 2.0.0 is installed but SDK 1.0.4 is defined in the global.json. The following environment variable is a workaround:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1

Run Asp.Net core on Visual Studio as 32bit

I just converted a project from MVC 4 to ASP.NET Core 1.0. This project does some pinvoke on a 32bit dll and when I try to debug it, I get that bad image exception.
If I deploy it using dotnet publish -c Release -r win7-x86 it works perfectly fine, but I can't debug it or run through visual studio.
You need to either publish the app as standalone app 32bit or, if it's a shared framework app, then you need to start it with a 32 bit dotnet.
If you already have the app running in 32 bit mode, then you can attach VS to it.
If you want VS to always use the 32 bit dotnet then you have to uninstall the dotnet in program files (or just remove it from the system PATH) and then install a dotnet that's 32 bit, making sure it's on the PATH. It's important to note that system PATH takes priority in Windows so adding something to the user's PATH will not work unless you remove the old one.
PS: I assume you're running on a 64 bit OS. Otherwise, you get the 32 bit dotnet by default.

Easy way to build and deploy (to Azure) ASP.NET 5 in Visual Studio Team Services

I have create a sample ASP.NET 5 application (pretty much the example one from New Solution), and pushed it to GIT hosted on Visual Studio Team Services (former Visual Studio Online). I want to set up continuous integration to Azure Web App (former Azure Web Site). I have tried to set it up from Azure portal itself, it did create a new build definition, but it fails to build ASP.NET 5. I have found a guide how to do this, but it never really worked for me, I get errors like this e.g.
Error parsing solution file at C:\a\1\s\Frontend\src\Frontend\Frontend.xproj: Exception has been thrown by the target of an invocation.
Predefined type 'System.Void' is not defined or imported
Another problem is that it seems it really takes a lot of time to install dnvm, get packages, etc. So all in all it's a pain to make it work.
So are there real alternatives for that or more importantly is Microsoft is planning to implement something like a Build ASP.NET 5, Deploy ASP.NET to Azure and such to make it easy as I suppose it's easy with the current ASP.NET 4 apps. I really hope that it will be an option soon since it's quite impossible to work with current build system.
For "System.Void" issue, please check the runtime version in "global.json" file and make sure it is consistent with the dependencies in "project.json" file.
For dnvm install issue, since AspNet5 runtime environment isn't installed on VSTS Hosted Build Agent for now and the different users may use different runtime versions, it requires the user to add a "PreBuild" PowerShell step to read the runtime version in "global.json" file and then install it. If you can make sure that you will always only use one version (For example: 1.0.0-rc1-update1), you can deploy your own build agent and install "1.0.0-rc1-update1" on it, then you can skip the dnvm installation during the build process.
Take a look on http://riffer.eu/wordpress/?p=112. There I have a solution vor asp.net core RC_1.
Amazingly you need only two powershell scripts - there is no compiling / visual studio necessary.

Make local TFS build agent to use v14 msbuild tools

I've got a couple of ASP.NET vNext applications and I want my CI server to also be able to build them. Both my local machine and the CI server are running VS2015 RC. Then we've got VS Online and a local build controller - which is the server mentioned.
However, I cannot get builds going since it seems to be looking for v12 tooling - which does not include anything DNX.
So - building the solution gives:
The Dnx Runtime package needs to be installed. See output window for
more details
It is installed - since it came with VS2015 RC, AFAIK. So I thought the build template isn't using v14 tooling. I downloaded the Default Git template v12. And indeed it says:
<this:Process.BuildProcessVersion>12.0</this:Process.BuildProcessVersion>
So I switched that to 14, uploaded template, ran build. Then:
Exception Message: The build controller used for this build does not
support the version of the template file used by the build definition.
The version of the template file is 14.0. The maximum supported
version for this build controller is 12.0.0.0.
So trying to solve this - got me to this forum question that states:
Then, instead of changing the BuildProcessVersion property, you need
to change the involved MSBuild version. Open the build process template, find the Run MSBuild for Project activity, change the ToolPath property to the 2013 version msbuild
So - I checked out the template - there is no ToolPath version. There is a ToolVersion property however - which I'll try setting to 14:
In short, my question is: how can I build ASP.NET vNext apps on my build server, that has VS2015RC installed - but is building using v12 tooling?
UPDATE
Seems that the problem is not as much in using the wrong tooling, but more in finding/using the correct DNX runtime while running under a service account ( which the TFS agent is doing ). I've added an issue for the DNX team: https://github.com/aspnet/dnx/issues/2239 .
use msbuild parameter /p:VisualStudioVersion=14.0 ,which can be added in build definition .

After upgrading solution to .NET framework 4.5 the daily deploy stopped working

We have with success been updating our development web site at a daily basis using msdeploy from TFS2010.
This was working fine until we upgraded to VS2012, our application from .NET Framework 4.0 to 4.5 and ASP.NET MVC from 3.0 to 4.0. It look like all is well and assemblies deployed but nothing has actually been deployed.
I have been looking into this for two days now and can't figure out why this is happening and now I am running out of ideas.
Below is part of my build script in the way it has been working before the upgrade.
<MSBuild
Projects="$(SolutionRoot)\My.Web\My.Web.csproj"
Properties="MvcBuildViews=False;AllowUntrustedCertificate=True;AuthType=Basic;Configuration=Dev;CreatePackageOnPublish=True;DeployIisAppPath=dev.myweb;DeployOnBuild=True;DeployTarget=MsDeployPublish;MSDeployPublishMethod=WMSvc;MsDeployServiceUrl=https://10.xxx.xxx.xxx:8172/MsDeploy.axd;UserName=UserName;Password=Password;UseMsdeployExe=True"
ContinueOnError="False"
/>
When the upgrade was initiated and my problem discovered we were using Web Deploy 2.0 but now we have upgraded to Web Deploy 3.0. I have also made sure we are building with ToolsVersion="4.0".
UPDATE --
msbuild.exe /p:AllowUntrustedCertificate=True
/p:AuthType=Basic
/p:Configuration=Dev
/p:CreatePackageOnPublish=True
/p:DeployIisAppPath=dev.myweb
/p:DeployOnBuild=True
/p:DeployTarget=MsDeployPublish
/p:MSDeployPublishMethod=WMSvc
/p:MsDeployServiceUrl=https://10.xxx.xxx.xxx:8172/MsDeploy.axd
/p:UserName=UserName
/p:Password=Password
/p:UseMsdeployExe=True
E:\Builds\1\WhatEver\Daily_Build\Sources\My.Web\My.Web.csproj
Now I also tried to run the above msbuild command from our TFS and no response which frustrates me completely. Nothing in the event log of TFS, nothing in log file no matter verbosity... Any ideas?
It does work using msdeploy directy like below;
<Exec Command=""C:\Program Files\IIS\Microsoft Web Deploy V3\MSDeploy.exe" -verb:sync -source:contentPath="E:\Builds\1\WhatEver\Daily_Build\Sources\My.Web\My.Web.csproj" -dest:contentPath="E:\dev.my.web",computername=https://10.xxx.xxx.xxx:8172/MsDeploy.axd,username=UserName,password=Password,authtype=Basic -allowUntrusted=True"
ContinueOnError="false" />
--
UPDATE 2 --
It appears Microsoft added a check for what type of projects that are publishable projects and our web application are not, since the Output Type is Class Library. This has been valid with v4.0 but apparently not for v4.5.
Anyone have an idea of what to do make it work again? Do I need to change the project type? Create publishing package up front and then deploy that? Or what?
--
Anyone else that has had the same problem? Have you found a solution to share?
Could there be an issue with version of MSBuild?
Here is what I would recommend. In VS2012 we have made it easy to automate publishing your web projects using the publish profiles which are created by the publish dialog. In your case create a new MSDeploy profile. When you create that profile we will save the settings into a file under Properties\PublishProfiles (or My Project\PublishProfiles for VB). The extension of this file will be .pubxml. Those files are actually MSBuild files, which you can customize if needed. You can continue to use the publish dialog as well. The password will be stored in a .user file and encrypted such that only you can decrypt it.
After you have created that profile you can publish with the command below if you are building the .sln file.
msbuild mysoln.sln /p:DeployOnBuild=true /p:PublishProfile=<ProfileName> /p:Password=<Password>
If you are building the .csproj/.vbproj then you need to tweak this a bit in the following way
msbuild mysoln.sln /p:DeployOnBuild=true /p:PublishProfile=<ProfileName> /p:Password=<Password> /p:VisualStudioVersion=11.0
More on why VisualStudioVersion is required at http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx.
Once you do this you will be able to build+publish just like you did previously. FYI we have shipped all these new web publish features for VS2010 in the Azure SDK https://www.windowsazure.com/en-us/develop/net/#.
Also in your question I noticed that you are specifying some custom properties, like MvcBuildViews. You can now place those properties directly inside the publish profile (the .pubxml file) if you want. Of course you can still pass them in on the command line if that makes more sense for your scenario.
More info on this at http://sedodream.com/2012/06/15/VisualStudio2010WebPublishUpdates.aspx.
If you take a look at the approach that we had for developers to automate publishing it was to specify properties and targets to be executed during the build. The problem with this approach is that this limits our ability to enhance the web publish experience. In the new release we have introduced an abstraction, the publish profile, which allows us to change the underlying targets of the web publish pipeline and your automation scripts will continue to run. Hopefully from this point forward you will not have to re-visit this issue.
I had much the same problem today. I too was trying to get a .NET 4.5 web application automatically deployed using a machine that did not have Visual Studio 2012 installed on it. There were a couple of minor differences in my situation, however: I was using TeamCity instead of TFS, and our solution was created with .NET 4.5 as opposed to being one that had been upgraded from .NET 4.0.
Nonetheless, I did have the same problem described. I'd use MSBuild to build the web app and deploy it to IIS, in much the same way. This approach worked fine on my dev machine. However, when I ran MSBuild on the CI server, it quite happily built the web app, but it stopped after that: no errors, no warnings, nothing, just a message that the build was successful. There wasn't the slightest hint of an attempt at deploying the app to IIS.
It seems MSBuild was missing the relevant targets to perform the web deployment.
The fix was to copy the folder C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web from my dev machine to the CI server, copying it to the same place on the CI server as it was on my machine.
Once I did that, MSBuild then grumbled about needing Web Deploy 3.0, but that was fixed easily enough. After installing that on the CI server too, MSBuild quite happily deployed the web app.
To extend Luke Woodward's answer:
I, too, found that deploying C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\ from my local machine to the build server was the fix.
However, the real fix is to install the Microsoft Web Developer Tools as part of the VS 2012 installation, which will create this folder, among other things. This addresses Ieppie's licensing objection.
I tested this by...
Deleting C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\
Running the VS 2012 installer and adding MS Web Dev tools.
Verifying that, after the install, C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\ was back.