DeploymentUnpublishable web api with webjob - azure

How can I publish my asp.net web api project created in Visual Studio 2015 which has a webjob to Azure using teambuild in TFS 2012?
The problem seems to revolve around msbuild. Locally and on the build machine, whenever I explicitly use the msbuild in C:\Program Files (x86)\Microsoft Visual Studio 14.0 it will work. When I use C:\Windows\Microsoft.NET\Framework64\v4.0.30319\, it gives me the the following output explaining that the deployment is unpublishable.
Target "_DeploymentUnpublishable: (TargetId:3)" in file "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets" from project "{poath}WebApi.csproj" (target "Publish" depends on it):
Task "Message" (TaskId:4)
Task Parameter:Text=Skipping unpublishable project. (TaskId:4)
Skipping unpublishable project. (TaskId:4)
Done executing task "Message". (TaskId:4)
When I queue a build from TFS I use the following arguments,
/t:Publish /ToolsVersion:14.0 /p:VisualStudioVersion=14.0 /p:ToolPath="C:\Program Files (x86)\MSBuild\14.0\Bin" /p:DeployOnBuild=true /p:PublishProfile=azureProfile.pubxml /p:Username=$user /p:Password=password

I never found a solution to this, but I was able to get the following hack to work.
Create a csproj file
Add a new <Target> like below
<Target Name="PushPackages">
<Exec Command=""C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" {WebApiWithWebjob}.csproj /p:DeployOnBuild=true;PublishProfile=Dev.pubxml;VisualStudioVersion=14.0;Password={password}" />
</Target>
Add the csproj file as the last item to build in the build definition

Related

Azure pipelines: error MSB4019 WebApplication.targets was not found

I created an episerver alloy project, which builds and runs fine in visual studio after setting up some nuget packages, and I can deploy to azure and run in azure from VS without issue.
I am now trying to get the build to work in pipelines.
Following the instructions, I added a "nuget restore" task, and pointed it at a NuGet.config.
This works.
Then it gets to the build stage, and gives:
D:\a\1\s\DxcAlloy.csproj(335,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.202\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.202\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.
I have no idea how to debug this. Some posts say that error can happen if you dont have visual studio installed, but I cant install visual studio on azure pipelines...
I removed the existing ".net restore" task, as it failed, and am guessing that just my nuget restore is all I need - this is a guess.
The pipeline "agent specification" is vs2017-win16
The project was created in VS 2019.
In desperation, I added a "Use .NET core" task, and set the version to the one which build is complaining is missing, i.e. 3.1.202.
This didn't help.
Any ideas?
If you build your project using dotnet build task. Below configuration in your .csproj file will be evaluated to C:\Program Files\dotnet\sdk\3.1.202\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets (What you see from the error)
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0</VSToolsPath>
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" />
Microsoft.WebApplication.targets usually exists in below location. That is why it errors out ...Microsoft.WebApplication.targets not found.
In Visual Studio 2017 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets"
In Visual Studio 2019 "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets"
The workaround for above issue is using Msbuid task or Visual Studio build task to build your projects. See below example:
- task: VSBuild#1
inputs:
solution: '**/*.csproj'
enabled: true
For your case, you also need to set agent specification to agent windows-latest. For visual studio 2019(v16.0) is only installed in agent windows-latest.
If you have to run your pipeline on agent "vs2017-win16" (only visual studio 2017(v15.0) is installed). You need to change the VSToolsPath in the .csproj file to <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0</VSToolsPath>
If you have to use dotnet build to build your projects. You can hard code the import path in csproj file as workaround.
<Import Project="C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" />

Running node.js tests locally in vstest.console.exe gives ... Error: An exception occurred while invoking executor 'executor://nodejstestexecutor/v1

I'm trying to get VSTS to run my Mocha unit tests, similar to how I've got them running in VS 2017.
I'm installed the Node JS Tools for Visual Studio and VS Test Explorer (after a restart) picks up the tests, and runs them.
But I can't get a VSTS build task to run them ???
Tried going through the notes on NTVS about running tests in VSTS but no joy getting it to work.
Moved onto the section about troubleshooting, and seeing if I can run the tests using my local vstest.console.exe ...
So far trying to run vstest ...
Error: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\Node.js Tools\Microsoft.NodejsTools.targets" was not found
quick fix ... added a copy of directory ... C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Node.js Tools ... to ... C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0
Error: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found
quick fix ... added a copy of directory ... C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets ... to ... C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0
Error: Could not find a part of the path C:\Repos\smc\BasicAzureExpress\BasicAzureExpress\ntvs\TestFrameworks
quick fix ... amend .nsproj to VS 2017 ... <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion> and a directory \TestFrameworks under \ntvs
... and then have the error ... Error: Missing generic test framework
So I'm left puzzled as to why VS 2017 can run the tests, but vstest.console.exe won't
First, the VSToolsPath value is empty if running in command line, then uses $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) path, but there aren’t necessary files of nodejs tool.
You can modify it like this (change Community to Professional if you are using vs2017 Professional):
<!--<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>-->
<VSToolsPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0</VSToolsPath>
Secondly, refer to these steps to run test on Hosted VS 2017 agent.
Modify project file (njsproj)
:
<!--<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>-->
<VSToolsPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0</VSToolsPath>
Copy NodeJsTools content in C:\Program Files (x86)\Microsoft Visual Studio\2017[Community, professional or enterprise]\Common7\IDE\Extensions\Microsoft to your ntvs folder
Add these files to source control and check in changes
Queue build with Hosted VS 2017 agent.

Compiling C# .Net from Command Line

I'm trying to compile a c# .net project only using command line so that I could create a bat file to compile and run the Selenium tests. I exported the code from SVN. And I opened the command prompt and am able to restore packages using below command.
And then when I try to compile with msbuild it could not reference the dll added in through the nuget. I know in visual studio through package manager console I can use a command (update -reinstall) and make it work, but how to do this without visual studio.
==== bat file ======
REM Restore External Pacakages
nuget restore packages.config -PacakgesDirectory D:\Testproject\packages"
msbuid TestProject.sln
Basically you need to reference Msbuild executable
C:\Windows\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe
OR
C:\Windows\Microsoft.Net\Framework64\v4.0.30319\MSBuild.exe
then you need to pass the .sln or .csproj file path (depends on your working folder) as parameter.
You can also specify the msbuild's targets ex. Clean, Rebuild, Build => As they exists in Visual Studio.
The final command could look like this:
Template:
{.NetFrameworkPath}\msbuild.exe {pathToSln} /t:{Build,Clean,Rebuild}
Examples
C:\Windows\Microsoft.Net\Framework64\v4.0.30319\MSBuild.exe TestProject.sln /t:Build
C:\Windows\Microsoft.Net\Framework64\v4.0.30319\MSBuild.exe TestProject.sln /t:Clean;Build

Running vcredist_x64.exe as a startup task for an Azure cloud service, osFamily="4"

There are several answers (e.g. this and this) and a blog post pointing out how to install the Visual C++ 2010 redistributable packages as part of the deployment of an Azure cloud service.
Firstly you add the vcredist_x64.exe to the web project and set its "Copy to output directory" property to "Copy if newer" or "Copy always". Then you do the same for a command file (in my case "InstallVC.cmd") which contains the single line:
vcredist_x64.exe /q /norestart
Then you edit the ServiceDefinition.csdef file to include the setting
<Startup>
<Task commandLine="InstallVC.cmd" executionContext="elevated" taskType="simple" />
</Startup>
within the role. The answers and the blog post go on to point out that the start-up task will hang if the osFamily setting on the ServiceConfiguration.csfg is set to osFamily="1" and that it needs instead to be set to osFamily="2".
Mine is set to osFamily="4", but the deployment fails. I get the error message Role has encountered an error and has stopped. Application startup task failed with exit code 5100.
How do you install the the Visual C++ 2010 redistributable packages as part of the deployment of an Azure cloud service using the more recent Azure OS families?
It failed because the Azure cloud service image already had a more up-to-date version of the Visual C++ redistributable packages installed, and so I did not need to install another. What had fooled me into thinking I did need it was that a DLL I use was failing to load its dependencies (as the screenshot below from Dependency Walker shows). But the failure to find the dependencies was not because the Visual C++ redistributable packages were missing, but instead because I was referencing the debug versions (e.g. MSVCP120D.DLL not MSVCP120.DLL). Swapping to 'release' fixed the missing dependencies problem for me, without needing any Azure deployment start-up tasks.

How to use msbuild to create csx output for Azure SDK 1.8?

I have a Visual Studio project with an Azure Cloud project that has one Web Role for a WCF Service. Rather than creating a cspkg by using the Package command in Visual Studio or with cspack, I need to create the same output that is in the project's csx folder with msbuild. However, if I run the following command in msbuild, the output doesn't have the same folder structure as the csx folder:
msbuild MyAzureProject.ccproj /p:configuration=debug /maxcpucount /p:outdir="c:\OutDir" /p:overwritereadonlyfiles=true /p:targetprofile="Cloud"
Instead it creates a _PublishedWebsites folder. Does anyone know how to create the contents of the csx folder manually by using the msbuild command-line (i.e. csx/roles/MyAzureRole/approot)?
You're just missing the targets switch.
Here's what works for me.
msbuild MyAzureProject.ccproj /p:configuration=debug /maxcpucount /p:outdir="c:\OutDir" /p:overwritereadonlyfiles=true /p:targetprofile="Cloud" /target:Clean;Publish

Resources