Exclude target framework from NuGet package - .net-core

How can i exclude specific target framework from nuspec (NuGet package) generation?
This is my csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net5.0-windows</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
dotnet pack command generates NuGet package that contains all target frameworks not only netstandard2.0 and net5.0
Generated nuspec:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ExampleLibrary</id>
<version>1.0.0</version>
<authors>ExampleLibrary</authors>
<description>Package Description</description>
<dependencies>
<group targetFramework="net5.0" />
<group targetFramework="net5.0-windows7.0" />
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
</package>

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net5.0-windows7.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);_ExcludeTargetFramework;_ExcludeTargetFrameworkDependency</GenerateNuspecDependsOn>
</PropertyGroup>
<Target Name="_ExcludeTargetFramework" AfterTargets="_GetTargetFrameworksOutput" BeforeTargets="_WalkEachTargetPerFramework">
<ItemGroup>
<_TargetFrameworks Remove="net5.0-windows7.0" />
</ItemGroup>
</Target>
<Target Name="_ExcludeTargetFrameworkDependency" AfterTargets="_WalkEachTargetPerFramework" BeforeTargets="GenerateNuspec">
<ItemGroup>
<_FrameworksWithSuppressedDependencies Include="net5.0-windows7.0" />
</ItemGroup>
</Target>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ExampleLibrary</id>
<version>1.0.0</version>
<authors>ExampleLibrary</authors>
<description>Package Description</description>
<dependencies>
<group targetFramework="net5.0" />
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
</package>

Remove all the dependencies (including TargetFramework)
In case you want to remove all dependencies (ie all target frameworks), the above solution won't work. Build will fail with the following error:
error MSB4044: The "ResolvePackageAssets" task was not given a value for the required parameter "TargetFramework".
Easy way
In case you just want to remove all dependencies, you can use the SuppressDependenciesWhenPacking property.
<PropertyGroup>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>
Full control of Nuspec
Otherwise, if you want to have a full control on the content of Nuspec after a first pass of generation, you can use a variation of this:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<UsingTask
TaskName="RemoveDependencies"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Nuspec ParameterType="System.String" Required="true"/>
</ParameterGroup>
<Task>
<Reference Include="System.Xml"/>
<Reference Include="System.Xml.Linq"/>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Xml.Linq"/>
<Code Type="Fragment" Language="cs">
<!-- Modify XML of the NuSpec -->
<![CDATA[
XElement doc = XElement.Load(Nuspec);
var dependenciesElement = doc.Descendants(XName.Get("dependencies", "http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd")).FirstOrDefault();
if (dependenciesElement != null)
{
dependenciesElement.Remove();
}
using (var textWriter = File.CreateText(Nuspec))
{
doc.Save(textWriter);
}]]>
</Code>
</Task>
</UsingTask>
<!-- From https://stackoverflow.com/questions/53762903/how-to-inject-a-custom-dependency-in-an-msbuild-nuget-pack-generated-nuspec -->
<!-- Disable nupkg generation before running pack -->
<Target Name="__DisablePacking" BeforeTargets="GenerateNuspec" Condition="$(NuspecFile) == '' And $(IsPackable) != 'false'">
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
</Target>
<!-- Remove .Net Standard 2.0 dependency as it's a native package -->
<!-- Modify the generated nuspec file and rerun the pack target -->
<Target Name="__ExcludeTargetFrameworkDependency" AfterTargets="Pack" Condition="$(NuspecFile) == '' And $(IsPackable) != 'false'">
<!-- Get the nuspec file name -->
<PropertyGroup>
<_NugetPackOutputAsProperty>#(NuGetPackOutput)</_NugetPackOutputAsProperty>
</PropertyGroup>
<ItemGroup>
<_NugetPackOutputAsItem Remove="#(_NugetPackOutputAsItem)"/>
<_NugetPackOutputAsItem Include="$(_NugetPackOutputAsProperty.Split(';'))" />
</ItemGroup>
<PropertyGroup>
<__NuspecFileName>%(_NugetPackOutputAsItem.Identity)</__NuspecFileName>
</PropertyGroup>
<Message Importance="High" Text="Remove Dependencies from $(__NuspecFileName)" />
<RemoveDependencies Nuspec="$(__NuspecFileName)" />
<!-- Invoke the Pack target again with packing enabled -->
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>true</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
<MsBuild
Projects="$(MSBuildProjectFullPath)"
Targets="Pack"
Properties="NuspecFile=$(__NuspecFileName);NoPackageAnalysis=true">
</MsBuild>
</Target>
</Project>
Notes:
GenerateNuspec target is doing both generation and packing. To disable packing after nuspec generation, we can use the ContinuePackingAfterGeneratingNuspec property.
Pack target is invoked twice (once by the user) and the second time with the system after first pack.
__ExcludeTargetFrameworkDependency rely on the Nuspec File value to be empty to execute on the first pack and to not execute on the second run. It obviously won't work if a Nuspec file is provided for the first run (with NuspecFile property).
Note the usage of And $(IsPackable) != 'false' to avoid invoking the target on test projects.
All NuGet targets like GenerateNuspec are located in C:\Program Files\dotnet\sdk\6.0.308\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets
All NuGet tasks for .NET 6, like PackTask, are located in C:\Program Files\dotnet\sdk\6.0.308\Sdks\NuGet.Build.Tasks.Pack\Desktop\NuGet.Build.Tasks.Pack.dll

Related

Console Application: Program does not contain a static 'Main' method suitable for an entry point - While Main exists

My .NET 5 project's Program.cs looks like this:
using System;
namespace XmlGenerator.Cli
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(("Boo!!!"));
}
}
}
And my project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Program.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="Master.xml" />
</ItemGroup>
<ItemGroup>
<Content Include="Program.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Resource Include="Master.xml" />
</ItemGroup>
</Project>
When I try and run the app with F5, I get the following error:
CS5001 Program does not contain a static 'Main' method suitable for an entry point
I certainly does contain a Main, so what could be wrong?
My solution was to delete all the ItemGroup elements from the project file, leaving just:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
</Project>

Microsoft.NET.Sdk.Web missing Web menu (ASP.NET)

I try to convert old ASP.NET MVC 5 (349C5851-65DF-11DA-9384-00065B846F21) projects to new format with Microsoft.NET.Sdk.Web.
One main difference is the missing Web menu under Project > Properties. How could I configure these settings in the new format?
Old ASP.NET Project:
New Microsoft.NET.Sdk.Web Project:
File Content of Microsoft.NET.Sdk.Web Project (vbproj)
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Deterministic>false</Deterministic>
<TargetFramework>net48</TargetFramework>
<OutputPath>$(SolutionDir)bin\ptc\$(Configuration)\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OptionStrict>On</OptionStrict>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputType>Library</OutputType>
<UseIISExpress>true</UseIISExpress>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
</ItemGroup>
</Project>

Unable to deploy to a local server folder asp.net successfully

I am new to asp.net
Below is my project file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GatherAllFilesToPublish">
</Target>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F5500ADD-969D-45A1-A175-0D60ECE982B2}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SampleWebService</RootNamespace>
<AssemblyName>SampleWebService</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<UseIISExpress>false</UseIISExpress>
<TargetFrameworkProfile />
<Use64BitIISExpress />
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</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\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Content Include="WebService.asmx" />
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="WebService.asmx.cs">
<DependentUpon>WebService.asmx</DependentUpon>
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommonLib\CommonLib.csproj">
<Project>{1B3AF307-D36B-498F-8618-B53688B4FFC6}</Project>
<Name>CommonLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile1.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile2.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile3.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile4.pubxml" />
<None Include="Properties\PublishProfiles\Profile1.pubxml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>64867</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- 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>
-->
</Project>
When i tried to deploy to a local server by folder,the bin/Release/Publish
does not contain anything.
Also tried the Debug mode too,bin/Debug/Publish folder contains nothing.
When i run publish,below is the following output,
1>------ Publish started: Project: SampleWebService, Configuration: Debug Any CPU ------
1>Connecting to D:\Project\Sample\SampleWebService\SampleWebService\bin\Release\publish\...
1>Publishing folder /...
1>Web App was published successfully file:///D:/Project/Sample/SampleService/SampleWebService/bin/Release/publish/
1>
========== Build: 0 succeeded, 0 failed, 2 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
The publish log indicates success but no files inside my publish folder.
i am using visual studio 2017 but the project files should be built using 2010
Based on the following lines:
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
V10.0 means visual studio 2010 ,am i right?
Anyone has any idea what is wrong,do i have to use visual studio 2010 to publish my project instead of the latest 2017 version?
Resolved:
The cause is i put the following lines in the project file to resolve the gatherallfilestopublish issue:
</Target>-->
Found another way to resolve the issue as outlined by below forum:
https://forums.asp.net/t/1838524.aspx?The+target+GatherAllFilesToPublish+does+not+exist
Re: The target GatherAllFilesToPublish does not exist
I fixed the issue by doing following modifications to the Project file. have VS 2012 and the web application was MVC 4
Unload the project and start editing the csproj file.
Added following lines.
10.0
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
Added following lines.(Note that some of the Import statments may already exisits. In such case you do not need to add them.
Project file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--<Target Name="GatherAllFilesToPublish">
</Target>-->
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F5500ADD-969D-45A1-A175-0D60ECE982B2}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SampleWebService</RootNamespace>
<AssemblyName>SampleWebService</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<UseIISExpress>false</UseIISExpress>
<TargetFrameworkProfile />
<Use64BitIISExpress />
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
</PropertyGroup>
<!--added-->
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<!--added-->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</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\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Content Include="WebService.asmx" />
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="WebService.asmx.cs">
<DependentUpon>WebService.asmx</DependentUpon>
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommonLib\CommonLib.csproj">
<Project>{1B3AF307-D36B-498F-8618-B53688B4FFC6}</Project>
<Name>CommonLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile1.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile2.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile3.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile4.pubxml" />
<None Include="Properties\PublishProfiles\FolderProfile5.pubxml" />
<None Include="Properties\PublishProfiles\Profile1.pubxml" />
</ItemGroup>
<!-- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />-->
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>64867</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- 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>
-->
</Project>

Microsoft.WebApplication.targets + Disable_CopyWebApplication=True doesn't prevent a csproj from creating a _PublishedWebsites folder

Got a dummy project + a console project which apply xslt transformations so they employ Microsoft.WebApplication.targets in their respective .csproj files like so:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{39560935-7551-4789-9666-4A48AD0FE3C7}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>...</RootNamespace>
<AssemblyName>...</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
**<Disable_CopyWebApplication>True</Disable_CopyWebApplication>**
</PropertyGroup>
[...]
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<UsingTask TaskName="TransformXml" AssemblyFile="$(VSToolsPath)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="BeforeBuild">
<Exec Command=".\.nuget\nuget.exe restore .\packages.config -PackagesDirectory .\..\packages" />
<Delete Files="Config\ConnectionStrings\ConnectionStrings.config" />
<Message Text="=====================================================================================================================================================" />
<Message Text="Applying XSLT transformations (Disable_CopyWebApplication='$(Disable_CopyWebApplication)') using 'Microsoft.WebApplication.targets' from:" />
<Message Text="" />
<Message Text="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" />
<Message Text="" />
<TransformXml Source="Config\ConnectionStrings\ConnectionStrings.base.config" Transform="Config\ConnectionStrings\ConnectionStrings.$(Configuration.Replace('dbg#', '').Replace('rls#', '')).config" Destination="Config\ConnectionStrings\ConnectionStrings.config" />
<Message Text="=====================================================================================================================================================" />
</Target>
To generate production builds for said projects in our build server we build them like so:
<MSBuild Projects="$(_solutionFile)"
Targets="$(TargetProject)"
Properties="Platform=$(Platform);OutputPath=$(PublishUrl);Configuration=$(Configuration);"
ToolsVersion="15.0"
/>
As shown above we employ
<Disable_CopyWebApplication>True</Disable_CopyWebApplication>
Still the _PublishedWebsite folder does get created anyways. What could we be missing here?
UPDATE
According to the debugging statements we placed in our .csproj file the "Microsoft.WebApplication.targets" which gets employed during the build is this one:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets"
The internal task which copies the "website" (exe in our case) is this:
<Target Name="_CopyWebApplication"
Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'"
DependsOnTargets="$(_CopyWebApplicationDependsOn)">
<CallTarget Condition="'$(OnAfter_CopyWebApplication)' != ''" Targets="$(OnAfter_CopyWebApplication)" RunEachTargetSeparately="true" />
</Target>
This task appears to be working as intended because it turns out that _PublishedWebsite doesn't contain any of the compiled dlls of the exe-project. It contains only the roslyn dlls/exes with the following folder structure:
<Project_Output_Folder>\_PublishedWebsites\<Project.Name.Here>\bin\roslyn
I take it that the inclusion of the nuget packages:
Microsoft.Net.Compilers
and/or
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
is what's causing the problem. The nuget packages being used are these:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net471" allowedVersions="[6.2.0]" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.8" targetFramework="net471" allowedVersions="[1.0.8]" />
<package id="Microsoft.Net.Compilers" version="2.6.1" targetFramework="net471" developmentDependency="true" allowedVersions="[2.6.1]" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net471" allowedVersions="[10.0.3]" />
<package id="Oracle.ManagedDataAccess" version="12.2.1100" targetFramework="net471" allowedVersions="[12.2.1100]" />
<package id="Oracle.ManagedDataAccess.EntityFramework" version="12.2.1100" targetFramework="net471" allowedVersions="[12.2.1100]" />
<package id="StructureMap" version="4.6.1" targetFramework="net471" allowedVersions="[4.6.1]" />
<package id="System.Reflection.Emit.Lightweight" version="4.3.0" targetFramework="net471" allowedVersions="[4.3.0]" />
</packages>
So I guess the question boils down to how can one make the Compilers package respect the dont-copy flag we are setting?

Compiling SASS using jRuby

I'm using jruby to compile scss files to css using ant build script.
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="compileSCSS" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<path id="JRuby">
<fileset file="libs/jruby-complete-1.7.18.jar"/> <!-- Location of JRuby jar file -->
</path>
<target name="compileSCSS">
<echo message="Compiling scss files..." />
<property name="filesIn" value="style.scss" />
<property name="fileOutDir" value="output/" />
<property name="root" value="." />
<script language="ruby" classpathref="JRuby">
<![CDATA[
require './libs/sass/lib/sass'
require './libs/sass/lib/sass/exec'
files = Dir.glob($project.getProperty('filesIn'))
files.each do |file|
opts = Sass::Exec::Sass.new(["--load-path", File.dirname(file), file, File.join($project.getProperty('fileOutDir'), File.basename(file, ".*") + ".css")])
opts.parse
end
]]>
</script>
<echo message="Done compiling SCSS source files." />
</target>
</project>
This is my build script. I'm using jruby 1.7.8 and SASS source code from github (version 3.4.9).
Its throwing exception :
javax.script.ScriptException: org.jruby.embed.EvalFailedException:
(NameError) uninitialized constant Sass::Exec::Sass
Please help. What could be the Issue?

Resources