I used VS 2019 to develop a simple extension. When I debug it (i.e. exp hive) it works both for VS 2019 and VS 2017. I could not figure out how to add VS 2015 to the startup menu, i.e. here:
So, I build the extension in Release (I changed it not to deploy it to the exp hive in Release) and run:
C:\RunAdjustLocalApplicationHostConfigScriptVSExt [master ↓1 ↑1]> git clean -qdfx
C:\RunAdjustLocalApplicationHostConfigScriptVSExt [master ↓1 ↑1]> msbuild /restore /p:Configuration=Release /v:m
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Restoring packages for C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\RunAdjustLocalApplicationHostConfigScriptVSExt.csproj...
Generating MSBuild file C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\obj\RunAdjustLocalApplicationHostConfigScriptVSExt.csproj.nuget.g.props.
Generating MSBuild file C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\obj\RunAdjustLocalApplicationHostConfigScriptVSExt.csproj.nuget.g.targets.
Restore completed in 817.27 ms for C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\RunAdjustLocalApplicationHostConfigScriptVSExt.csproj.
RunAdjustLocalApplicationHostConfigScriptVSExt -> C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\bin\Release\RunAdjustLocalApplicationHostConfigScriptVSExt.dll
RunAdjustLocalApplicationHostConfigScriptVSExt -> C:\RunAdjustLocalApplicationHostConfigScriptVSExt\src\bin\Release\RunAdjustLocalApplicationHostConfigScriptVSExt.vsix
C:\RunAdjustLocalApplicationHostConfigScriptVSExt [master ↓1 ↑1]> .\src\bin\Release\RunAdjustLocalApplicationHostConfigScriptVSExt.vsix
C:\RunAdjustLocalApplicationHostConfigScriptVSExt [master ↓1 ↑1]>
And get this:
I tried to play with the dependencies and the prerequisites and the best I could get is a clean install dialog suggesting it can be installed to all the three versions of VS, but in reality the extension was broken - there was an error about missing references. In any case it is a failure now and it was a failure then.
The extension is very simple:
RunAdjustLocalApplicationHostConfigScriptVSExt.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MinimumVisualStudioVersion>16.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<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>
<SchemaVersion>2.0</SchemaVersion>
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{A887F433-7EE5-47FC-9EE7-D06389A2E793}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RunAdjustLocalApplicationHostConfigScriptVSExt</RootNamespace>
<AssemblyName>RunAdjustLocalApplicationHostConfigScriptVSExt</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<UseCodebase>true</UseCodebase>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>true</CopyOutputSymbolsToOutputDirectory>
<StartAction>Program</StartAction>
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployExtension>False</DeployExtension>
</PropertyGroup>
<ItemGroup>
<Compile Include="VSPackage.cs" />
</ItemGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.202" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.3.2099" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\VSPackage.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="VSPackage.resx">
<DependentUpon>VSPackage.cs</DependentUpon>
<MergeWithCTO>true</MergeWithCTO>
<ManifestResourceName>VSPackage</ManifestResourceName>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
source.extension.vsixmanifest
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="RunAdjustLocalApplicationHostConfigScriptVSExt.c6c6888b-d5e0-4861-96be-bb0cc8812d6d" Version="0.0.19323.36172" Language="en-US" Publisher="Kharitonov, Mark" />
<DisplayName>RunAdjustLocalApplicationHostConfigScriptVSExt</DisplayName>
<Description xml:space="preserve">Runs the script Tools\\MSBuild\\AdjustLocalApplicationHostConfig.ps1, if found.</Description>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0, 16.0)" />
<InstallationTarget Version="[16.0,)" Id="Microsoft.VisualStudio.Community" />
<InstallationTarget Version="[14.0,15.0)" Id="Microsoft.VisualStudio.Community" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
<Dependency d:Source="Installed" Id="Microsoft.VisualStudio.MPF.16.0" DisplayName="Visual Studio MPF 16.0" Version="[16.0,17.0)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.1.28811.260,17.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
</PackageManifest>
VSPackage.cs
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Events;
using Task = System.Threading.Tasks.Task;
namespace RunAdjustLocalApplicationHostConfigScriptVSExt
{
[Guid(PACKAGE_GUID_STRING)]
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[ProvideAutoLoad("B0BAC05D-0000-41D1-A6C3-704E6C1A3DE2", PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasSingleProject_string, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class VSPackage : AsyncPackage
{
public const string PACKAGE_GUID_STRING = "812e8a96-c440-49cb-84d8-531b2d99f696";
private string m_scriptPath;
private bool m_solutionOpen;
protected override Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
SolutionEvents.OnAfterOpenSolution += SolutionEvents_OnAfterOpenSolution;
SolutionEvents.OnBeforeOpenSolution += SolutionEvents_OnBeforeOpenSolution;
SolutionEvents.OnAfterOpenProject += SolutionEvents_OnAfterOpenProject;
return Task.FromResult(default(object));
}
private void SolutionEvents_OnAfterOpenSolution(object sender, OpenSolutionEventArgs e)
{
m_solutionOpen = true;
RunScript();
}
private void SolutionEvents_OnAfterOpenProject(object sender, OpenProjectEventArgs e)
{
RunScript();
}
private void RunScript()
{
if (!m_solutionOpen || m_scriptPath == null)
{
return;
}
var psi = new ProcessStartInfo
{
FileName = "powershell",
Arguments = $"-NoProfile -ExecutionPolicy Bypass -NonInteractive -File {m_scriptPath}",
CreateNoWindow = true,
LoadUserProfile = false,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
};
Process.Start(psi);
}
private void SolutionEvents_OnBeforeOpenSolution(object sender, BeforeOpenSolutionEventArgs e)
{
m_solutionOpen = false;
m_scriptPath = null;
var dir = e.SolutionFilename;
while (dir.Length > 3)
{
dir = Path.GetDirectoryName(dir);
var scriptPath = Path.Combine(dir, "Tools\\MSBuild\\AdjustLocalApplicationHostConfig.ps1");
if (File.Exists(scriptPath))
{
m_scriptPath = scriptPath;
return;
}
}
}
}
}
All it does is run a special script after a solution or a project is loaded.
I am failing to understand what needs to be done for it to install and work cleanly on VS 2019, VS 2017 and VS 2015. The reason I must support the latter is because we still have Silverlight code that needs to be debugged.
EDIT 1
Following the answer by Sergey Vlasov I changed the source.extension.vsixmanifest and also downgraded the NuGet dependencies:
Microsoft.VisualStudio.SDK - from 16.0.202 to 15.9.3
Microsoft.VSSDK.BuildTools - from 16.5.5 to 15.9.3032
And it load into the three versions, but works only for VS 2017 and VS 2019. In VS 2015 there are no errors, but also there are no effects of the extension. As if it was installed, but not used.
EDIT 2
Well, I switched to VS 2015 and developed it all there. Because I do not see how to use the v14 SDK on VS 2019 or VS 2017.
Works great in VS 2015, but installing it to VS 2017 shows this:
The following extensions are not compatible with the selected version of Visual Studio. Installation may cause Visual Studio to be unstable.
- RunAdjustLocalApplicationHostConfigScriptVSExt
How can it be avoided?
P.S.
This question is related to How to make VS 2017 run some custom code after any project is loaded?
At the end what worked for me is this:
Create the extension on VS 2015. Not optimal at all, but I have it installed anyway.
Reference the nuget package https://www.nuget.org/packages/Microsoft.VisualStudio.Sdk.BuildTasks.14.0/
After saving it all, I opened it in VS 2017 and migrated to Package References.
csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<UseCodebase>true</UseCodebase>
<OldToolsVersion>14.0</OldToolsVersion>
</PropertyGroup>
<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>
<SchemaVersion>2.0</SchemaVersion>
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{E21DB471-B7B3-4A7D-A737-8260B01D5AC6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RunAdjustLocalApplicationHostConfigScriptVSExt</RootNamespace>
<AssemblyName>RunAdjustLocalApplicationHostConfigScriptVSExt</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>true</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>true</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files %28x86%29\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployTargetInstanceId />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployExtension>False</DeployExtension>
</PropertyGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VSPackage.cs" />
</ItemGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE100, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE90, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.CommandBars, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\VSPackage.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="VSPackage.resx">
<MergeWithCTO>true</MergeWithCTO>
<ManifestResourceName>VSPackage</ManifestResourceName>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Shell.14.0">
<Version>14.3.25407</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.12.0">
<Version>12.0.30110</Version>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
<Version>15.0.26201</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
source.extension.vsixmanifest
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="RunAdjustLocalApplicationHostConfigScriptVSExt.Ceridian.c02cad06-ed15-4097-9626-316a0104a436" Version="1.0" Language="en-US" Publisher="Kharitonov, Mark" />
<DisplayName>RunAdjustLocalApplicationHostConfigScriptVSExt</DisplayName>
<Description xml:space="preserve">Runs the script Tools\\MSBuild\\AdjustLocalApplicationHostConfig.ps1, if found.</Description>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[14.0,17.0)" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
<Dependency Id="Microsoft.VisualStudio.MPF.14.0" DisplayName="Visual Studio MPF 14.0" d:Source="Installed" Version="[14.0]" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,)" DisplayName="Visual Studio core editor" />
</Prerequisites>
</PackageManifest>
The only problem is this dialog when installing in VS 2017:
And I would dearly love to get rid of it. But I do not know how. I guess it would be another question.
EDIT 1
Finally nailed with the help of these two posts (in this order):
http://www.visualstudioextensibility.com/2017/01/10/its-time-to-change-the-vsix-manifest-of-your-extension-to-v3-for-visual-studio-2017-compatibility/
https://madskristensen.net/blog/how-to-upgrade-extensions-to-support-visual-studio-2019/
I have updated the code snippet above to reflect the changes.
To make the extension installable in VS 2015-2019, you need to adjust source.extension.vsixmanifest:
Remove Dependency d:Source="Installed" Id="Microsoft.VisualStudio.MPF.16.0" DisplayName="Visual Studio MPF 16.0" Version="[16.0,17.0)"
Change CoreEditor Version="[16.1.28811.260,17.0)" to Version="[15.0,)".
To make it work in VS 2015-2019, you need to make sure to reference only VS 2015 assemblies (they usually have 14.0 in the name).
I've upgraded Visual Studio from 2010 to 2015 but i'm getting a project incompatible error as per the screenshot below:
When i open the ****.csproj_deploy.wdproj file here's the contents, company name redacted:
<?xml version="1.0" encoding="utf-8"?>
<!--
Microsoft Visual Studio 2008 Web Deployment Project
http://go.microsoft.com/fwlink/?LinkID=104956
-->
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectName>*********</ProjectName>
<BuildDir>..\..\..\..\target</BuildDir>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.30319</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4981E0AB-A55B-46AE-B55F-B607E3B4EAA5}</ProjectGuid>
<SourceWebPhysicalPath>..\..\webapp</SourceWebPhysicalPath>
<SourceWebProject>{BF29C57D-D568-4195-9DE5-E5F179E19A0C}|src\main\webapp\*********.csproj</SourceWebProject>
<SourceWebVirtualPath>/*********.csproj</SourceWebVirtualPath>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>$(BuildDir)\$(Configuration)</OutputPath>
<EnableUpdateable>true</EnableUpdateable>
<UseMerge>true</UseMerge>
<SingleAssemblyName>*********.csproj_deploy</SingleAssemblyName>
<DeleteAppCodeCompiledFiles>false</DeleteAppCodeCompiledFiles>
<UseWebConfigReplacement>false</UseWebConfigReplacement>
<DeleteAppDataFolder>false</DeleteAppDataFolder>
<VirtualDirectoryAlias>
</VirtualDirectoryAlias>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<OutputPath>$(BuildDir)\$(Configuration)</OutputPath>
<EnableUpdateable>true</EnableUpdateable>
<UseMerge>true</UseMerge>
<SingleAssemblyName>*********.csproj_deploy</SingleAssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'goss-test|AnyCPU' ">
<EnableUpdateable>true</EnableUpdateable>
<UseMerge>true</UseMerge>
<UseWebConfigReplacement>false</UseWebConfigReplacement>
<SingleAssemblyName>*********.csproj_deploy</SingleAssemblyName>
<OutputPath>$(BuildDir)\$(Configuration)</OutputPath>
<DeployPath>E:\dotnet-sites\eastrenintranet</DeployPath>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '*********-intranet-dev|AnyCPU' ">
<EnableUpdateable>true</EnableUpdateable>
<UseMerge>true</UseMerge>
<UseWebConfigReplacement>false</UseWebConfigReplacement>
<SingleAssemblyName>*********.csproj_deploy</SingleAssemblyName>
<OutputPath>$(BuildDir)\$(Configuration)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '*********-intranet-live|AnyCPU' ">
<EnableUpdateable>true</EnableUpdateable>
<UseMerge>true</UseMerge>
<UseWebConfigReplacement>false</UseWebConfigReplacement>
<SingleAssemblyName>*********.csproj_deploy</SingleAssemblyName>
<OutputPath>$(BuildDir)\$(Configuration)</OutputPath>
</PropertyGroup>
<ItemGroup>
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\.svn\**\*" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\bin\*.xml" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\lucene\**\*" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\media\**\*" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\obj\**\*" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\*.csproj" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.user" />
<ProjectReference Include="..\..\webapp\*********.csproj">
<Project>{BF29C57D-D568-4195-9DE5-E5F179E19A0C}</Project>
<Name>*********</Name>
</ProjectReference>
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\cache\**\*" />
<ProjectReference Include="..\..\webapp\*********.csproj">
<Project>{BF29C57D-D568-4195-9DE5-E5F179E19A0C}</Project>
<Name>eastren-intranet</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<IncludeInBuild Include="$(SourceWebPhysicalPath)\**\*" Exclude="#(ExcludeFromBuild)" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="CopyFilesToOutputDirectory" BeforeTargets="Rebuild">
<Copy SourceFiles="#(IncludeInBuild)" DestinationFolder="$(BuildDir)\$(Configuration)\%(RecursiveDir)" />
</Target>
<Target Name="BeforeBuild">
<RemoveDir Directories="$(BuildDir)" />
</Target>
<Target Name="BeforeMerge">
</Target>
<Target Name="AfterMerge">
</Target>
<Target Name="Rebuild" BeforeTargets="BeforeBuild">
<Message Text="*** Target: Rebuild - BEGIN" />
<!-- Copy in any configuration files overwriting any previous ones -->
<ItemGroup>
<ConfigFiles Include="..\..\config\$(Configuration)\**\*.*" Exclude="..\..\config\$(Configuration)\**\.svn\**" />
</ItemGroup>
<Message Text="*** Target: Rebuild - Copying configuration files" />
<Copy SourceFiles="#(ConfigFiles)" DestinationFolder="$(BuildDir)\$(Configuration)\%(RecursiveDir)" />
<!-- Create a ZIP archive of the entire built site -->
<ItemGroup>
<ZipFiles Include="$(BuildDir)\$(Configuration)\**\*.*" />
</ItemGroup>
<MakeDir Directories="$(BuildDir)" Condition="!Exists('$(BuildDir)')" />
<Message Text="*** Target: Rebuild - Zipping work directory $(BuildDir)\$(Configuration)\ " />
<Zip Files="#(ZipFiles)" WorkingDirectory="$(BuildDir)\$(Configuration)\" ZipFileName="$(BuildDir)\$(ProjectName)-$(Configuration)$(Version).zip" ZipLevel="9" />
<!-- Auto deploy new site if on test -->
<ItemGroup Condition="$(DeployPath) != ''">
<SiteFiles Include="$(DeployPath)\**\*.*" Exclude="$(DeployPath)\.htaccess" />
</ItemGroup>
<Message Text="*** Target: Rebuild - Removing deployment directory $(DeployPath) " />
<Delete Condition="$(DeployPath) != ''" Files="#(SiteFiles)" />
<Message Text="*** Target: Rebuild - Unzipping site file $(DeployPath) " />
<Unzip Condition="$(DeployPath) != ''" ZipFileName="$(BuildDir)\$(ProjectName)-$(Configuration)$(Version).zip" TargetDirectory="$(DeployPath)" />
<Message Text="*** Target: Rebuild - END " />
</Target>
</Project>
How do i resolve this issue?
I can build the solution ok without any errors and the site displays ok on localhost. MSBUILD also runs ok and on the face of it, i can't see an issue with the output.
Please advise
thanks
Visual Studio 2013/2015 don't support Setup and deployment -projects out of the box. Install extension to enable those:
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2015InstallerProjects
Using MSBuild I include a solution>
<ItemGroup>
<ProjectToBuild Include="$(SVNLocalPath)\$(SolutionName)"> </ProjectToBuild>
</ItemGroup>
I need to include all the *.csproj file from the solution with the condition of the proj file contain or define a property; for example if x.csproj contain a defined property "TestProjectType" would like to include the project into my itemGroup
something like this
<Target Name = "TestProperties">
<Message Text="TestProperties"/>
<ItemGroup>
<AllProj Include="$(SVNLocalPath)\*.csproj"/>
<AllTestProj Include="%(AllProj.Identity)" Condition="%(AllProj.ProjectTypeGuids)=={3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"/>
</ItemGroup>
<Message Text="#(AllTestProj )"/>
</Target>
Thanks
You can achieve that through custom task.
A simple sample to check a property (test) in all projects exclude current project of current solution:
<UsingTask TaskName="GetPropertyTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<ProjectFile ParameterType="System.String" Required="true" />
<BuildOutput ParameterType="System.String[]" Output="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml"/>
<Reference Include="Microsoft.Build"/>
<Using Namespace="Microsoft.Build" />
<Using Namespace="Microsoft.Build.Evaluation" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var properties = new Dictionary<string, string>
{
{ "Configuration", "$(Configuration)" },
{ "Platform", "$(Platform)" }
};
//Log.LogMessage(MessageImportance.High, "customLog");
// Log.LogMessage(MessageImportance.High, ProjectFile);
var collection = new ProjectCollection(properties);
var project = collection.LoadProject(ProjectFile);
ProjectProperty pp = project.Properties.Where(p => p.Name == "MyCustomProperty").FirstOrDefault();
string customValue = pp==null?"empty":pp.EvaluatedValue;
BuildOutput = new String[] { customValue };
]]></Code>
</Task>
</UsingTask>
<Target Name="AfterBuild">
<GetPropertyTask ProjectFile="%(ProjectToScan.FullPath)">
<Output ItemName="ProjectToScanOutput" TaskParameter="BuildOutput"/>
</GetPropertyTask>
<Message Text="ClassLibrary1" Importance="high" Condition="'%(ProjectToScanOutput.Identity)' == 'test'" />
</Target>
More information, please refer to this article.
I need to exclude abc.Test.csproj from the .sln file during team build compilation.
I have tried using /ignoreprojectextensions=.Test.csproj, but doesnt work for my purpose. Please help me in accomplishing this.
You would create a new Configuration (Debug and Release are the default ones) and in this new Configuration, you would not-build the specified .csproj.
Then you would build to that Configuration.
See:
Does Msbuild recognise any build configurations other than DEBUG|RELEASE
APPEND
WITHOUT doing a new/custom Configuration, this is the only solution I can reason.
Put the below xml'ish code .. in a file called "MyBuild.proj" , save it, and then call
msbuild.exe MyBuild.proj
..
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
<PropertyGroup>
<WorkingDirectory>.</WorkingDirectory>
</PropertyGroup>
<Target Name="AllTargetsWrapped">
<CallTarget Targets="ShowReservedProperties" />
<CallTarget Targets="BuildOtherProjects" />
</Target>
<Target Name="BuildOtherProjects">
<ItemGroup>
<ProjectReferencesExcludes Include="$(WorkingDirectory)\UnitTests.csproj" />
<ProjectReferencesExcludes Include="$(WorkingDirectory)\SomeOtherProject.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReferences Include="$(WorkingDirectory)\**\*.*proj" Exclude="#(ProjectReferencesExcludes)" />
</ItemGroup>
<Message Text="List of projs to be built:"/>
<Message Text="#(ProjectReferences->'"%(fullpath)"' , '%0D%0A')"/>
<Message Text=" "/>
<Message Text=" "/>
<MSBuild
Projects="#(ProjectReferences)"
Targets="Build">
<Output
TaskParameter="TargetOutputs"
ItemName="AssembliesBuiltByChildProjects" />
</MSBuild>
<Message Text=" "/>
<Message Text=" "/>
<Message Text="List of AssembliesBuiltByChildProjects:"/>
<Message Text="#(AssembliesBuiltByChildProjects->'"%(fullpath)"' , '%0D%0A')"/>
<Message Text=" "/>
<Message Text=" "/>
</Target>
<Target Name="ShowReservedProperties">
<Message Text="MSBuild: $(MSBuild)"/>
<Message Text="MSBuildBinPath: $(MSBuildBinPath)"/>
<Message Text="MSBuildExtensionsPath: $(MSBuildExtensionsPath)"/>
<Message Text="MSBuildExtensionsPath32: $(MSBuildExtensionsPath32)"/>
<Message Text="MSBuildExtensionsPath64: $(MSBuildExtensionsPath64)"/>
<Message Text="MSBuildLastTaskResult: $(MSBuildLastTaskResult)"/>
<Message Text="MSBuildNodeCount: $(MSBuildNodeCount)"/>
<Message Text="MSBuildOverrideTasksPath: $(MSBuildOverrideTasksPath)"/>
<Message Text="MSBuildProgramFiles32: $(MSBuildProgramFiles32)"/>
<Message Text="MSBuildProjectDefaultTargets: $(MSBuildProjectDefaultTargets)"/>
<Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)"/>
<Message Text="MSBuildProjectDirectoryNoRoot: $(MSBuildProjectDirectoryNoRoot)"/>
<Message Text="MSBuildProjectExtension: $(MSBuildProjectExtension)"/>
<Message Text="MSBuildProjectFile: $(MSBuildProjectFile)"/>
<Message Text="MSBuildProjectFullPath: $(MSBuildProjectFullPath)"/>
<Message Text="MSBuildProjectName: $(MSBuildProjectName)"/>
<Message Text="MSBuildStartupDirectory: $(MSBuildStartupDirectory)"/>
<Message Text="MSBuildThisFile: $(MSBuildThisFile)"/>
<Message Text="MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)"/>
<Message Text="MSBuildThisFileDirectoryNoRoot: $(MSBuildThisFileDirectoryNoRoot)"/>
<Message Text="MSBuildThisFileExtension: $(MSBuildThisFileExtension)"/>
<Message Text="MSBuildThisFileFullPath: $(MSBuildThisFileFullPath)"/>
<Message Text="MSBuildThisFileName: $(MSBuildThisFileName)"/>
<Message Text="MSBuildToolsPath: $(MSBuildToolsPath)"/>
<Message Text="MSBuildToolsVersion: $(MSBuildToolsVersion)"/>
</Target>
</Project>
Note, that if you put a csproj in the Exclude list BUT another csproj references/depends on it, it will be built (regardless of what you "exclude").
I have a Visual Studio solution with 2 Windows Phone 7 projects. One is the main project, the other links its xaml pages from the first.
I try to modify the .csproj file of the second project in order to preprocess its linked pages by a custom task. My modifications are based upon the sample solution of this blog post :
Xaml pages are indeed processed by my custom task but the output files are not used in continuation of the compiling process. I guess this is the involved portion of code :
<ItemGroup>
<ProcessedPages Include="#(Page->'%(Link)')" />
<!-- Remove the original (linked) pages so that they are not compiled. -->
<Page Remove="#(Page)" Condition="('%(Page.Link)' != '')" />
<!-- Include the processed pages instead. -->
<Page Include="#(ProcessedPages)" />
</ItemGroup>
How to modify it so MarkupCompilePass1 use output file of the PreprocessorTask task ?
By the way, I don’t get what is the value of #(Page->'%(Link)') during compilation.
Compelete project file for reference :
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="XamlPreprocessor.PreprocessorTask" AssemblyFile="C:\Users\Louis\Documents\visual studio 2010\Projects\XamlPreprocessor\XamlPreprocessor\bin\Debug\XamlPreprocessor.exe" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C835DF63-2335-4946-B343-186E556C4FEC}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ProcessorTest</RootNamespace>
<AssemblyName>ProcessorTest</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<TargetFrameworkProfile>WindowsPhone71</TargetFrameworkProfile>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<SilverlightApplication>true</SilverlightApplication>
<SupportedCultures>
</SupportedCultures>
<XapOutputs>true</XapOutputs>
<GenerateSilverlightManifest>true</GenerateSilverlightManifest>
<XapFilename>ProcessorTest.xap</XapFilename>
<SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
<SilverlightAppEntry>ProcessorTest.App</SilverlightAppEntry>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE;WP8</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Phone" />
<Reference Include="Microsoft.Phone.Interop" />
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Xml" />
<Reference Include="mscorlib.extensions" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Appli2\MainPage.xaml.cs">
<Link>MainPage.xaml.cs</Link>
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="..\Appli2\Page2.xaml.cs">
<Link>Page2.xaml.cs</Link>
<DependentUpon>Page2.xaml</DependentUpon>
</Compile>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<None Include="Properties\AppManifest.xml" />
<None Include="Properties\WMAppManifest.xml" />
</ItemGroup>
<ItemGroup>
<Content Include="ApplicationIcon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Background.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SplashScreenImage.jpg" />
</ItemGroup>
<ItemGroup>
<Page Include="..\Appli2\MainPage.xaml">
<Link>MainPage.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="..\Appli2\Page2.xaml">
<Link>Page2.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<MarkupCompilePass1DependsOn>
$(CompileXamlDependsOn)
PreprocessXaml;
</MarkupCompilePass1DependsOn>
</PropertyGroup>
<Target Name="PreprocessXaml">
<!-- Run the preprocessor on every page that is added to the project as link. The processed file will be saved at the link position. -->
<!--<Exec Condition="('%(Page.Link)' != '')" Command="XamlPreprocessor.exe "%(Page.FullPath)" "%(Page.Link)""/>-->
<PreprocessorTask Symbols="$(DefineConstants)" File="%(Page.FullPath)" OutName="%(Page.Link)" Condition="('%(Page.Link)' != '')" />
<Copy SourceFiles="%(Page.Link)" DestinationFolder="C:\Users\Louis\Desktop\temp\" />
<ItemGroup>
<ProcessedPages Include="#(Page->'%(Link)')" />
<!-- Remove the original (linked) pages so that they are not compiled. -->
<Page Remove="#(Page)" Condition="('%(Page.Link)' != '')" />
<!-- Include the processed pages instead. -->
<Page Include="#(ProcessedPages)" />
</ItemGroup>
</Target>