Showing posts with label msbuild. Show all posts
Showing posts with label msbuild. Show all posts

Thursday, September 20, 2018

ASP.NET Core- wrong processPath in generated web.config

Leave a Comment

I have rather strange problem.

One of the applications we are working on stopped working after publish to Azure Web App. Everything works ok locally. After long investigation, the culprit is that the web.config generated by the build (in VSTFS) has this:

<aspNetCore processPath=".\SomeServiceName.Api " stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />

While the correct one is: <aspNetCore processPath=".\SomeServiceName.Api.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />

Note the missing .exe.

The build output of the project is set to Console Application. It's ASP.NET Core app, running on full framwork. The build is run using Visual Studio Build task in VSTS, with following MSBuildArguments:

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)"

If I run the build on my dev machine, using MSBuild cli, with the same command line arguments, I get this:

<aspNetCore processPath="dotnet" arguments=".\SomeServiceName.Api.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />

The project is using <Project Sdk="Microsoft.NET.Sdk.Web">.

I'm guessing I could just add web.config to the project (it's not there at all now) and have it in source control the way I want, that should fix my immidiate problem of broken deployments. But I would like to know:

  1. The web.config genrated by build on VSTS is obviously wrong. Is that a bug in Microsoft.NET.SDK.Web thing?
  2. I don't have access to the actuall build server. I'm guessing that the only reasonable explanation is that someone updated .net core SDK, which is why the behaviour changed. Does this make sense? Does the msbuild targets come from .NET Core SDK, or is that part of visual studio?
  3. I'm getting different web.config on my machine. Why is that?

2 Answers

Answers 1

I had exactly the same problem, and I solved it last week. We had 2 ASP.Net Core projects, one showing the issue, the other didn't have the issue. So we compared the 2 .csproj files.

Turns out that in our case, all we needed to do was delete the

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">   <PlatformTarget>AnyCPU</PlatformTarget> </PropertyGroup> 

properties from the .csproj; once that was done, MSBuild correctly created the web.config, including the .exe at the end of the processPath.

Answers 2

A few options for getting the .exe in there. Each of these methods worked for me:

  1. Switch the build configuration from Debug (the default) to Release:

    dotnet publish -c Release or msbuild argument /p:Configuration=Release

  2. Create a web.config the way you want it in the root of your project and then tell the SDK not to touch it by adding the following to your project file:

    <PropertyGroup> <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled> </PropertyGroup>

  3. Specify your target runtime as one of the win-* runtimes listed at https://docs.microsoft.com/en-us/dotnet/core/rid-catalog. Here's the code that appears to be adding the exe extension:

    https://github.com/aspnet/websdk/blob/6b898ad0a39329ab5f0db281a9c1712e4303ed61/src/Publish/Microsoft.NET.Sdk.Publish.Targets/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets#L44

Read More

Sunday, May 27, 2018

Can I Pass Compilation Constants to a Project Reference?

Leave a Comment

If I have a <ProjectReference> reference, is there any way to pass a conditional compilation value to that project? Something like this (I know <DefineConstants> doesn't exist like this, it's just to illustrate the need):

<ProjectReference Include="..\DataProducer\DataProducer.csproj">   <DefineConstants>WAS_SET</DefineConstants> <ProjectReference> 

Therefore, if there's a class in that project like this:

    public sealed class ProduceValue     {         public string Produce()         { #if WAS_SET             return "WAS SET"; #else             return "NOTHING WAS SET"; #endif         }     } 

Then by passing that value during compilation or not, I could get different output.

1 Answers

Answers 1

The ProjectReference item allows adding the metadata fields Properties and UndefineProperties to allow maninpulating the set of "global" properties that are used to build project references. You could make use of this by passing in a global property to the referenced project like this:

<ProjectReference Include="..\DataProducer\DataProducer.csproj">   <Properties>DefineConstants=WAS_SET</Properties> <ProjectReference> 

The effect of this now being a global property to the referenced project is that it will override any definition/update of DefineConstants defined statically in the project - this may also include any added configuration constant (DEBUG).

Read More

Wednesday, March 21, 2018

Have MSBuild only build targets that require building

Leave a Comment

So long story short, we've got a situation of having multiple solutions with assembly references between them. Used to be, we had to go and build these solutions in the correct order to have our dependencies built correctly.

I'm trying to make things easier by using MSBuild tasks to first restore nuget on the dependent solution, then build the dependencies for you, ie:

<Target Name="BeforeBuild" Condition="'$(Configuration)'=='Debug'">     <Message Importance="high" Text="Kicking off internal dependency build for $(MSBuildProjectName) in Configuration=$(Configuration), Platform=$(Platform), OutDir=$(OutDir)" />     <!--Build the dependencies-->     <Message Importance="high" Text="Restoring MyDependencyProject NuGet External Packages..." />     <Exec Command="..\..\bin\nuget.exe restore ..\MyProject\MyDependencyProject\MyDependencyProject.sln" />     <Message Importance="high" Text="Building MyDependencyProject dependency..." />     <MSBuild Projects="..\MyProject\MyDependencyProject\MyDependencyProject\MyDependencyProject.csproj" Targets="Build" Properties="Configuration=$(Configuration)" />     <Message Importance="high" Text="Building MyDependencyProject2 dependency..." />     <MSBuild Projects="..\MyProject\MyDependencyProject\MyDependencyProject\MyDependencyProject2.csproj" Targets="Build" Properties="Configuration=$(Configuration)" /> </Target> 

This works great! What used to be 7(!) separate solutions we had to open and build, is now condensed to 2 (we build our C++ COM libraries, then build our C# libraries).

One problem - while this is easier, it is very slow. I've been going over the diagnostic output from MSBuild, and it seems that the way I've set this up is forcing the dependencies to be rebuilt every single time. If I had set Targets="Rebuild" I would expect this, but I thought Targets="Build" would build ONLY IF a project was out of date (or had a file set to):

<CopyToOutputDirectory>Always</CopyToOutputDirectory>  

in the project file). I can not find any message in the diagnostic output to explain why the MSBuild target is rebuilding these dependencies, even if the dependencies have not been touched.

Why does MSBuild do a full rebuild of dependency projects that have not been altered with the above tasks?

Edit - More information

I see the following:

Target "IncrementalClean: (TargetId:324)" in file "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets" from project "c:\Source\MyProject\MyDependencyProject\MyDependencyProject\MyDependencyProject.csproj" (target "CoreBuild" depends on it): 

0 Answers

Read More

Wednesday, February 21, 2018

Publish (FTP) fails from MSBUILD

Leave a Comment

If I publish with my website with Visual Studio (using FileSystem) it works fine.

Now I'm attempting to do the same from Powershell.

.\MSBuild.exe $sln /p:PublishProfile=MyTestProfile /p:PublishProvider=FileSystem /p:CreatePackageOnPublish=False /p:DeployOnBuild=False /p:VisualStudioVersion=15.0 /v:diag 

The above is based upon the output window (of Visual Studio) when I publish (using diagnostic output). Things are copied and pasted to avoid typos.

The problem I have is it never publishes!

I am now shown the following message from Powershell:

Build FAILED.

"C:\Users\me\source\repos\Test03\WebApplication2\WebApplication2.csproj" (default target) (1) -> C:\Users\me\source\repos\Test03\WebApplication2\WebApplication2.csproj(265,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

This issue appears to be well documented here on SO but, I already have VS installed, and this isn't a build server. It's all being done on my one machine... However, if I try to get to the path C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets it doesn't exist. I have C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\ but within this folder only 1 folder called FileTracker.

This now confuses me more because it works from within Visual Studio, but not within Powershell.

1 Answers

Answers 1

Resolved with

.\MSBuild.exe $sln /p:PublishProfile=MyTestProfile /p:PublishProvider=FileSystem /p:CreatePackageOnPublish=False /p:DeployOnBuild=True /p:AspnetMergePath="C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools" /p:VisualStudioVersion=15.0 #/v:diag 

You may not have the path for the correct visual studio version. Downloading .NET Core SDK should provide this https://www.microsoft.com/net/download/windows

However, you may need to update to the correct path for the build path (where msbuild.exe exists).

I then had to add /p:AspnetMergePath="C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools" manually for reasons I don't understand. I understand that it coudln't find this path, but I didn't understand why it can't find the path when VS could!

Read More

Tuesday, August 22, 2017

MVC 5 - Precompiling views only works from the command prompt

Leave a Comment

I have a strange issue that hopefully someone can help me with. I got a new laptop and I'm trying to publish the same ASP.NET MVC 5 project on the new machine with precompiled views. However, when I do a publish with "Precompile during publishing" option checked, it does not create the precompiled views. Now, if I copy the exact command that it ran and run it in the Command Prompt, the precompiled views are created.

Here's the details. Both machine have Windows 10 Anniversary Update (Version 1607) with Visual Studio 2013 Update 5. Publishing the app on the old machine with the same publish profile generates the precompiled views. On the new machine, publishing from the "Publish Web" dialog runs without errors, but no precompiled views are generated. I then copied this exact command to the Command Prompt that VS used to precompile:

C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p C:\MyApp\obj\Release\AspnetCompileMerge\Source -c C:\MyApp\obj\Release\AspnetCompileMerge\TempBuildDir 

When I ran it, it created the precompiled views in the TempBuildDir\bin directory!

The only difference I can think of between the machines are the Windows Updates.

Any ideas? Thanks.

1 Answers

Answers 1

Do you use the x64 verson of Windows?

Also you can try set $(AspnetCompilerPath) manually:

msbuild.exe /p:AspnetCompilerPath="C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe" 

or add it to your project:

<PropertyGroup>   <AspnetCompilerPath Condition=" '$(AspnetCompilerPath)'=='' " >C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe</AspnetCompilerPath> </PropertyGroup> 

I've made this assumption, because the Microsoft.Web.Publishing.AspNetCompileMerge.targets file contains the string:

 We can't use the in-place aspnet_compiler because it will output to the aspnet temp folder which is only suiteable to run on the current machine. 
Read More

Monday, July 24, 2017

error MSB3147: Could not find required file 'setup.bin' Publish to Local FAILURE

Leave a Comment

After scouring the internet and discussing this in chat here, I'm finally asking a new question about an old error.

I'm using Visual Studio Enterprise 2015 on Windows 10.

The question and answers on this are from 2011 MSBuild: error MSB3147: Could not find required file 'setup.bin'.

This question and the accepted answer were written in 2012, the other answers are from 2015, with one from 2016, that is not helpful Could not find required file 'setup.bin'.

The target build for the project is 4.0. I'm running a psl script that has only been run from another local machine.

I keep getting this error:

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4769,5): error MSB3147: Could not find required file 'setup.bin' in 'C:\dev\xxx\src\xxx\Engine'. [C:\dev\xxx\src\xxx \xxx.csproj] Publish to Local FAILURE

I have tried every solution from every answer. The only one that works is from this answer

<BootstrapperEnabled>false</BootstrapperEnabled>  

Which is a problem if it is needed to be set to true.

I've also followed this answer on MSDN. This blog.

I added registry keys:

enter image description here

enter image description here

I'm also noticing that Windows 10 has .NET framework built in, and it misses 4.0.

enter image description here

I had uninstalled the dotNetFx40_Full_setup.exe and ran a repair on Visual Studio to allow it to install the sdks as needed. This did not help.

I have an MSBuild exe where it is supposed to be according to this:

enter image description here

I'm wondering if it's because I'm missing .NET sdk 4.0.
Is it the version of bootstrapper? I don't know how to fix it. Does anyone know how to solve this on Windows 10?

1 Answers

Answers 1

The bootstrapper is responsible for the initialization of an application built using the Composite Application Library.

When you set <BootstrapperEnabled>false</BootstrapperEnabled>, the initialization of an application built will be omit. If you set it true, the initialization will be executed, then you will get that error “MSB3147: Could not find required file 'setup.bin'”.

According to your description and images, I found that you have the MSBuild 12.0, but added the value of GenericBootstrapper to the MSBuild 4.0 registry key.

Starting in Visual Studio 2013, the MSBuild Toolset version is the same as the Visual Studio version number.

So please check the registry value of GenericBootstrapper with the version 12.0. If the value is not exists or incorrect, please add it with value “C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\Bootstrapper”. enter image description here

Read More

Monday, June 5, 2017

How to enable build debugging in MSVS 2015?

Leave a Comment

I have a project in MSVS 2015 which keeps spuriously rebuilding every time, i.e. building always launches MSBuild which then gives a bunch of "All outputs are up-to-date." messages followed by "Build succeeded." instead of just doing nothing, as it should. In the previous versions of MSVS there was a (never documented AFAIK) way to enable verbose debug logging to quickly find the reason for this as explained e.g. here. Unfortunately this doesn't seem to do anything with MSVS 2015.

Does anybody know what has replaced it or some other way of debugging this problem?

1 Answers

Answers 1

I had a very similar problem checking out and unzipping some files that had a future date on them. This caused the entire project to rebuild even with no changes.

On *nix system, I would have used touch to fix, but on Windows I used the FOR command on cmd.exe:

FOR /R %I in (*.*) do copy /b "%I" +,, 

Which updates the timestamp to current (iirc).


Before I figured it out, I tried to change the verbosity of the build process. You need to restart VS2015 after changing this setting:

Tools->options Projects&Settings->Build and Run;  Build Output : Verbose


Also, turn on the startup banner using Configuration Properties -> C/C++ -> General. This gives you some more build commands.

Read More

Tuesday, May 2, 2017

How can I use Microsoft.Net.Compilers at solution level?

Leave a Comment

I want to start using Microsoft.Net.Compilers to simplify work with our build server. However, I could only get it to work at a per-project level, by adding the package to all projects.
This is problematic because the package would have to be added to each new created project. This could lead to a case where the code compiles on the developer's machine (which has the latest compiler), but would fail on the build server. We have many projects (over 100), so this is relatively common.

Is there a way of using Microsoft.Net.Compilers at solution level?

If there is no supported way, is there a command line tool I would not have to install on the build server? Alternatively, is this not an intended usage of these tools?

2 Answers

Answers 1

If in VS 2017 (update 1, build numbers >= 15.1.*) you can use the MSBuild integrated PackageReference mechanism instead of packages.config which was previously only available for .net core and .net standard project types. See the PackageReference documentation as well as the NuGet blog post announcing the support, especially the section "What about other project types that are not .NET Core?".

The idea is to switch from installing a package and adding it to packages.config for restore to just specifying an MSBuild items in the csproj file. This can be set up for new projects in VS: Switch from packages.config to ProjectReference

A new feature of MSBuild 15 is that it supports automatically including files in the directory hierarchy that have special names. Those are Directory.Build.props and Directory.Build.targets which will get included before (props) and after (targets) your project file's content (there is a bug with the .targets version for multi targeting projects for which a fix is about to be released).

If you create a Directory.Build.props file with the following content at the solution level, all projects in the directory hierarchy below it will inherit it's content and you can force a NuGet dependency onto each project:

<Project>     <ItemGroup>         <PackageReference Include="Microsoft.Net.Compilers" Version="2.1.0"/>     </ItemGroup> <Project> 

Answers 2

For existing projects in the solution:

Right-click your solution > Manage NuGet Packages for Solution...

... Or:

Tools > Library Package Manager > Manage NuGet Packages for Solution...

Then add it to all the projects by browsing for your package, then checking the top checkbox, and clicking install.

Source : http://stackoverflow.com/a/8653312/7007466


For the new projects:

Create a template mimicking the original one for each type of project you need (Console, Library etc...) and adding the package to it.

  • Create a project.

    Note: Use only valid identifier characters when naming a project that will be the source for a template. A template exported from a project named with invalid characters can cause compilation errors in future projects based on the template.

  • Edit the project until it is ready to be exported as a template.
  • As appropriate, edit the code files to indicate where parameter replacement should take place.
  • On the File menu, click Export Template. The Export Template wizard opens.
  • Click Project Template.
  • If you have more than one project in your current solution, select the projects you want to export to a template.
  • Click Next.
  • Select an icon and a preview image for your template. These will appear in the New Project dialog box.
  • Enter a template name and description.
  • Click Finish. Your project is exported into a .zip file and placed in the specified output location, and, if selected, imported into Visual Studio.

If you have the Visual Studio SDK installed, you can wrap the finished template in a .vsix file for deployment by using the VSIX Project template.

Source : https://msdn.microsoft.com/en-us/library/xkh1wxd8.aspx

If someone has an easier way than creating templates, I'll gladly take it.

Read More

Sunday, March 19, 2017

Why is there a need for a separate item in my MSBuild file?

Leave a Comment

There are many articles (like this and this) that show how to add files to be published, and they all say to add something like this to the publish profile (.pubxml):

<Target Name="CustomCollectFiles">   <ItemGroup>     <_CustomFiles Include="..\Extra Files\**\*" />     <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">       <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>     </FilesForPackagingFromProject>   </ItemGroup> </Target> 

Why is there a need for the new _CustomFiles item? Why not simply <FilesForPackagingFromProject Include="..\Extra Files\**\*">? I tried it, and for some reason this causes every file in the project to end up in the deployed Extra Files folder. Can someone explain me this behaviour please?

2 Answers

Answers 1

Since you are asking about why this is required, I will have to dive deep into what this code means to explain what you're seeing. <Message /> is our friend!

The meaning of %

Let's first look at what % means by using it in a <Message> task:

<ItemGroup>   <_CustomFiles Include="..\Extra Files\**\*" /> </ItemGroup>  <Message Text="File: %(_CustomFiles.Identity)" /> 

When you run this, you'll get the following output:

File: ..\Extra Files\file1.txt File: ..\Extra Files\file2.txt File: ..\Extra Files\file3.txt ... File: ..\Extra Files\etc.txt 

Basically, the Message task runs once for each item in the item group, because we used %.

What's in the item group?

Let's take a peek at the item group before we even make any changes to it. When this task begins, FilesForPackagingFromProject already has all of the files in them, with various metadata properties, including DestinationRelativePath. Let's see it by adding just this to our task:

<Message Text="File: %(FilesForPackagingFromProject.Identity) -> %(FilesForPackagingFromProject.DestinationRelativePath)" /> 

This outputs:

File: ..\obj\TempBuildDir\PrecompiledApp.config -> PrecompiledApp.config File: ..\obj\TempBuildDir\Web.config -> Web.config File: ..\obj\TempBuildDir\App_Themes\theme.css -> App_Themes\theme.css ... 

It's important to realise that this item group is not empty to begin with. You are trying to add items to it.

The working code

When you have sub-elements in an element that has %, they apply once to each iteration, so let's now look at the working code:

<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">   <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath> </FilesForPackagingFromProject>  <Message Text="File: %(FilesForPackagingFromProject.Identity) -> %(FilesForPackagingFromProject.DestinationRelativePath)" /> 

For each item in _CustomFiles, we include it into the FilesForPackagingFromProject item group and set the DestinationRelativePath metadata property to the appropriate RecursiveDir/Filename values - basically the ones that apply for the current element being looked at. Let's look at what this outputs:

File: ..\obj\TempBuildDir\PrecompiledApp.config -> PrecompiledApp.config File: ..\obj\TempBuildDir\Web.config -> Web.config File: ..\obj\TempBuildDir\App_Themes\theme.css -> App_Themes\theme.css ... File: ..\Extra Files\file1.txt -> Extra Files\file1.txt File: ..\Extra Files\file2.txt -> Extra Files\file2.txt File: ..\Extra Files\file3.txt -> Extra Files\file3.txt ... File: ..\Extra Files\etc.txt -> Extra Files\etc.txt 

Including just a single file

If you wanted to include just a single file, you can do so as follows:

<FilesForPackagingFromProject Include="..\Extra Files\file1.txt">   <DestinationRelativePath>Extra Files\file1.txt</DestinationRelativePath> </FilesForPackagingFromProject> 

This has no % to expand anywhere, so it does exactly what you would expect: it includes a single file into the output.

The broken code

Now let's try to include a single file, but without hard-coding the path and instead using the % expression from the original code:

<FilesForPackagingFromProject Include="..\Extra Files\file1.txt">   <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath> </FilesForPackagingFromProject>  <Message Text="File: %(FilesForPackagingFromProject.Identity) -> %(FilesForPackagingFromProject.DestinationRelativePath)" /> 

There are % here so things get expanded, but because this doesn't have a % in the item group element, the expansion works differently and things get pear-shaped:

File: ..\obj\TempBuildDir\PrecompiledApp.config -> PrecompiledApp.config File: ..\obj\TempBuildDir\Web.config -> Web.config File: ..\obj\TempBuildDir\App_Themes\theme.css -> App_Themes\theme.css ... File: ..\Extra Files\file1.txt -> Extra Files\PrecompiledApp.config File: ..\Extra Files\file1.txt -> Extra Files\Web.config File: ..\Extra Files\file1.txt -> Extra Files\theme.css 

So instead of adding file1.txt to the item group once, it iterates over the entire collection and adds file1.txt once for each file already in it. RecursiveDir is not set in this context, while Filename/Extension are the original filename of each file in the group.

Hopefully you can see now that this will create a file for each file in your entire deployment, but in a flat tree, and notably, the contents will be that of file1.txt rather than the original file.

When you include a wildcard instead of just one file, the same thing happens for every file matched by the wildcard.

How to fix this

Stick with the %(_CustomFiles) fix. Hopefully you will now see why it's necessary and how it does what it does. I do believe this is how you are supposed to do this: here's another question about it, with an answer that recommends this approach.

Answers 2

That is because the CustomCollectFiles task doesn't have an intrinsic understanding of recursion with wildcard. The ItemGroup does the wildcard magic, the new _CustomFiles item will create a associative array, then ItemGroup would invoke the CustomCollectFiles task to handle the associative array. So there is a need for the new _CustomFiles item.

Read More

Friday, March 17, 2017

Delete folders after publish with new ASP.NET CORE 1.1 csproj file format

Leave a Comment

I am publishing an ASP.NET Core 1.1 application and I need to delete from the output a few folders (fr;nl;pt) created by a library (Fluent Validation):

<ItemGroup>   <FluentValidationExcludedCultures Include="fr;nl;pt">     <InProject>false</InProject>   </FluentValidationExcludedCultures> </ItemGroup>  <Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild">   <RemoveDir Directories="@(FluentValidationExcludedCultures->'$(OutputPath)%(Filename)')" /> </Target> 

But this does not work and the folders are still copied ... Then I tried:

<ItemGroup>   <Content Include="fr" CopyToPublishDirectory="Never" />   <Content Include="nl" CopyToPublishDirectory="Never" />   <Content Include="pt" CopyToPublishDirectory="Never" /> </ItemGroup> 

But this didn't work either ...

Does anyone has any idea how to make this work?

1 Answers

Answers 1

Try to edit your csproj file and add the following section for each of the directories that you do not want to include when publishing:

<ItemGroup>     <PublishFile Remove="directory\**" /> </ItemGroup> 
Read More

Wednesday, February 1, 2017

.Net build is failing due to invalid applicationHost.config

Leave a Comment

Folks,

Am trying to run a build using the below command line however there is a prompt everytime which is causing trouble. I have to address this manually and cannot run automated builds.

$currentScriptPath = (pwd).Path $solution = "$($currentScriptPath)\foobar_Msi.sln" $project = "$($currentScriptPath)\foobarSetup\foobarSetup.vdproj" $BuildLog = "$($currentScriptPath)\buildlog.txt" $devEnvCom = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.com" $devEnvExe = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" $PackagePath = "$($currentScriptPath)\ReleasePackage" . . . & $devEnvCom $solution /project $project /Build release /Out $BuildLog 

An error occured when applying the IIS Express settings to server URL 'http://localhost:2943/' for project 'Foobar.UI'. You may have to manually edit the applicationHost.config file and make the changes for your site to run correctly

I cleared IISAppsettings in document, tried non-interactive command line arguments, changed the binding in build servers applicationHost.Config file and nothing works.

1 Answers

Answers 1

On your development machine, copy/move the solution to a local path that exactly matches the one it will be in when the automated build is run. Open the solution in Visual Studio 2012, Save All, and add the hidden [solution path].VS\applicationHost.config to source control.

Read More

Friday, June 10, 2016

How to have MSBuild process all SSIS projects

Leave a Comment

I have successfully followed the blog 1 to get MSBuild to build an SSIS project. This involved creating a dll and an MSBuild script. The process works correctly for any single project file.

I'm looking for help in getting this process to work for each .dtproj file that is defined in a solution (.sln) file. I have read about MSBuild Batching 2 but it refers to items that are defined in the build script. I want it to work with whatever projects are in the solution file so I don't have to manually edit a script every time a project is add/removed/moved.

Any suggestions or links to approaches? Thanks for taking the time to read my question!

blog

MSBuild Batching

1 Answers

Answers 1

If you don't want to with the batch option you can try something like this:

<Project  xmlns="http://schemas.microsoft.com/developer/msbuild/2003"           DefaultTargets="Build">    <PropertyGroup>     <MySolution Condition="'$(MySolution)'==''">MySolution.sln</MySolution>     <Configuration Condition="'$(Configuration)'==''">Release</Configuration>     <SSISServer Condition="'$(SSISServer)'==''">MyServer</SSISServer>     <PROJECTNAME Condition="'$(PROJECTNAME)'==''">MyProjectName</PROJECTNAME>   </PropertyGroup>    <UsingTask TaskName="DeploymentFileCompilerTask" AssemblyFile="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.SqlServer.IntegrationServices.Build.dll" />   <UsingTask TaskName="DeployProjectToCatalogTask" AssemblyFile="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.SqlServer.IntegrationServices.Build.dll" />    <Import Condition="Exists('$(MySolution).metaproj')" Project="$(MySolution).metaproj"/>    <Target Name="Initialize">     <MSBuild Projects="$(MySolution)" Properties="Configuration=$(Configuration);MSBuildEmitSolution=1" Targets="Clean" />   </Target>    <Target Name="Build">     <Message Text="**************Building SSIS project: %(ProjectReference.FullPath) for configuration: $(Configuration)**************" />     <DeploymentFileCompilerTask         InputProject="%(ProjectReference.FullPath)"         Configuration="$(CONFIGURATION)"         ProtectionLevel="DontSaveSensitive">     </DeploymentFileCompilerTask>   </Target>    <Target Name="Deploy">     <Message Text="**************Deploying SSIS project: %(ProjectReference.FullPath) for configuration: $(Configuration)**************" />     <Message Text="..\%(ProjectReference.RootDir)%(ProjectReference.Directory)\bin\$(CONFIGURATION)\%(ProjectReference.FileName)%(ProjectReference.Extension).ispac"/>      <DeployProjectToCatalogTask         DeploymentFile="..\%(ProjectReference.RootDir)%(ProjectReference.Directory)\bin\$(CONFIGURATION)\%(ProjectReference.FileName)%(ProjectReference.Extension).ispac"         Instance="$(SSISServer)"         Folder="$(PROJECTNAME)"         CreateFolder="true"/>   </Target> </Project> 

This will generate a MsBuild project version of the solution including all the included projects (read about msbuildemitsolution), after that it will import the generated "msbuild solution" (.metaproj) and use the ProjectReference items to execute them one by one using the "DeploymentFileCompilerTask" and "DeployProjectToCatalogTask"

You can call this like this:

For Build:

msbuild SSIS.proj /t:Initialize

msbuild SSIS.proj /t:Build

For Deploy:

msbuild SSIS.proj /t:Initialize

msbuild SSIS.proj /t:Deploy

The Initialize target will generate the "msbuild solution" and you need to call this target to ensure the content is updated.

You can pass any of the Properties defined at the beginning on the command line to use the script for different solutions.

If you need different "Folders" for each project, you could use the "Filename" item metadata (i.e. %(ProjectReference.Filename) instead of $(PROJECTNAME)).

Note: This is not a final working script, but it should give a clear idea of the proposed solution, if you comment the "DeploymentFileCompilerTask" and "DeployProjectToCatalogTask" nodes of the script you can execute it and see some messages in the console with the data that will be processed.

Read More

Friday, April 29, 2016

How to execute power shell script when a build is stopped in build explorer

Leave a Comment

I have got a requirement wherein I need to execute a PowerShell script when someone stops a running build in TFS -> Build explorer.

Is there any event or method that I can hook my code into to achieve that?

For far I only know Pre & Post build events but those wont help me here.

Note: we are using TFS for source control and for builds. And using Octopus Deploy for development on various environments.

1 Answers

Answers 1

Write TFS Server side plugin, which can monitor for that information by subscribing to the events you're interested of.

If you google for "how to create TFS server side plugins" you'll find plenty tutorials how to create one.

For ex: https://roadtoalm.com/2012/03/29/create-tfs-event-subscription-programmatically-with-tfs-api/

You could subscribe to BuildStatusChangedEvent event, and then do something.

Read More