error in csproj - duplicate item - visual-studio-2010

I have error from visual studio 2010:
Error 1 The item "CrossDomainService.svc.cs" was specified more than once in the "Sources" parameter. Duplicate items are not supported by the "Sources" parameter. WcfServiceDomain
and from msbuild
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(160,9)
: error MSB3105: The item "CrossDomainService.svc.cs" was specified more than o
nce in the "Sources" parameter. Duplicate items are not supported by the "Sources" parameter. [C:\inetpub\Wwwroot\axaptaWcfConnection\WcfServiceDomain\WcfSer
viceDomain.csproj]
My file is csproj:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8D40933A-E036-4CD0-9003-314A692724D5}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WcfServiceDomain</RootNamespace>
<AssemblyName>WcfServiceDomain</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
</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>
<PlatformTarget>x86</PlatformTarget>
</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.Web.ApplicationServices" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Configuration" />
<Reference Include="System.Drawing" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.Services" />
</ItemGroup>
<ItemGroup>
<Content Include="ClientAccessPolicy.xml" />
<Content Include="CrossDomainService.svc" />
<Content Include="Service1.svc" />
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="CrossDomainService.svc.cs">
<DependentUpon>CrossDomainService.svc</DependentUpon>
</Compile>
<Compile Include="ICrossDomainService.cs" />
<Compile Include="Service1.svc.cs">
<DependentUpon>Service1.svc</DependentUpon>
</Compile>
<Compile Include="IService1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>51421</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
</Project>
I not see any duplicate :/ Any idea from this error ??

I was facing the same problem in my solution with the same error for one of the source file,
I fixed it out as follows,
Check for the file name for which the error is given.
Find out in which project the file is included.
Open the .csproj file for that particular project (This file can be found in the directory where solution is placed).
Search for the file name for which the error is thrown in the .csproj file.
You will find two entries of the line such as
<Compile Include="duplicate.aspx.cs">
<SubType>ASPXCodeBehind</SubType>
<DependentUpon>Duplicate.aspx</DependentUpon>
</Compile>
<Compile Include="duplicate.aspx.cs">
<SubType>ASPXCodeBehind</SubType>
<DependentUpon>Duplicate.aspx</DependentUpon>
</Compile>
Delete any one line from one of them.
Save the changes.
Reload the project your error must have gone.

For those who encountered the same problem, nothing helped them and they do not want to recreate the project: Try to delete YourPojectName.csproj.user file. It helped me. I modified the .csproj manually before and the modification introduced (somehow) probably some discrepancy to the two files.

You could just open the solution in a regular text editor and remove the dups by hand

Easy!
Just right clic in your project and select "Unload Project"
Right clic one again and edir your_project.csproj
Search a duplicate tag for the file mentioned in the error message.
Save and right clic to choose "Reload Project"

I think I encountered the same problem not too long ago.
The solution was to remove the subtype from the web.config, i.e:
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
To:
<Content Include="Web.config">
</Content>
Now, those have been added again, I'm not sure why. Searching for more information hasn't cleared it up yet.
See:
<Subtype>Designer</Subtype> Added then removed by Visual Studio on load/unload

I have the same problem and the solution was to shorten and sanitize the directory name (it was a backup one and has date and time separated by a semicolon).

Open the file WcfServiceDomain.csproj with a text editor and look for CrossDomainService.svc.cs
It'll probably be there twice. Just delete one of the lines and the project will work again.

I know this is old post but I found this better solution which could help others who are currently having this issue.
In Solution Explorer, select the file/files specified in the error
message or the folder containing these files.
Right-click then select Exclude From Project.
Click the Refresh button.
Select the files or folder again, right-click then select Include In
Project.

The main clue in the error message is - "Sources". This is a misconfiguration in .csproj file, the build targets are being imported twice. It normally stays at the end of the .csproj file under import. File name is some kind of misleading, I was looking with the file name I can only find it once in the whole project file. When I looked in the import I've got similar to this;
<Import Project="..\..\LonestarWeb\packages\Telerik.Sitefinity.Feather.10.2.6651\build\Telerik.Sitefinity.Feather.targets" Condition="Exists('..\..\LonestarWeb\packages\Telerik.Sitefinity.Feather.10.2.6651\build\Telerik.Sitefinity.Feather.targets')" />
<Import Project="\packages\Telerik.Sitefinity.Feather.10.2.6651\build\Telerik.Sitefinity.Feather.targets" Condition="Exists('..\..\LonestarWeb\packages\Telerik.Sitefinity.Feather.10.2.6651\build\Telerik.Sitefinity.Feather.targets')" />
Remove the one you don't need. Reload the solution and you can now compile.

Wildcards!
See the example below from a cproj file. The Class.cs Include is already taken care of by the wildcard Include below it so it has now been Included twice. You obviously want to lose the specific Class.cs Include.
<Compile Include="..\Folder\Class.cs">
<Link>Class.cs</Link>
</Compile>
<!-- lots of things in between ...scroll scroll scroll -->
<Compile Include="..\Folder\*.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>

I had to delete the class from the project and recreating it again to solve this problem.

The way that I fixed this issue was by going to the location where the file was which was included in the error and find that there was two of the same files. Delete one of them and it should work.
I had to undo the pending changes afterwards as the files then went missing, but after a re-build it worked.

What I did was that I renamed the file in question. Then cleaned the solution (by clicking on Build > Clean Solution). Then Built the solution.
Then renamed the file to original filename. Then cleaned the solution and built the solution again.
It worked for me. I dont know if it ll work for u.

For me I unload the project,
Edit .csproj file,
search for the filename which was showing in error
<ItemGroup>
<Compile Include="Controllers\BaseUserContext.cs" />
</ItemGroup>
It was not showing multiple time (BaseUserContext.cs), only 1 tag was there, so I removed it and works without an error.

I had a similar issue. I opened an already existing VS solution for the first time one my machine. This VS solution was not created by a human beeing, but generated from an openAPI-specification using Swagger-Editor.
Initially the solution did not have any problems at all. I could build the solution and I was also able to run the code. The actual issue appeared as soon as I added a new class to any of the projects of the solution (just: 'Right Click' > 'Add' > 'New Item' > 'Class'). No matter what name I chose for that new class I always got the compilererror
The item "MyNewClass.cs" was specified more than once in the "Sources" parameter. Duplicate items are not supported by the "Sources" parameter.
Once I removed the class, everything was fine again.
Besides VS, I also have JetBrains Rider (2020.1) on my machine. So I opened the same solution in Rider and added a new class. In Rider, the error did not appear. I was able to add as many classes as I wanted.
In the end, it came down to wildcards, as 'CAD bloke' already mentioned in his answer above.
The original solution generated by the abovementioned Swagger-Editor contains this piece of XML in it's .csproj-file:
<ItemGroup>
<Compile Include="**\*.cs" Exclude="obj\**" />
</ItemGroup>
If I add a new class using VS it becomes this, which in turn causes the error:
<ItemGroup>
<Compile Include="**\*.cs" Exclude="obj\**" />
<Compile Include="Api\NewClass.cs" />
</ItemGroup>
VS is not aware of the wildcard in use. If I add a class using Rider, the additional <Compile Include="Api\NewClass.cs" /> is not added. Rider is aware of the wildcard!
Seems like the guys at JetBrains are better at dealing with microsofts csproj-format, than microsoft.
How to fix this
To fix this issue in the end, I excluded all source files from the project ('right click' > 'Exclude from Project'). Then I closed the solution and opened the .csproj file in a text editor. I removed the <Compile Include="**\*.cs" Exclude="obj\**" /> from the .csproj-file. After removing the line I opened the solution again in VS and included all source files again ('Show all files' (in solution explorer) > 'right click' > 'Include in project').
Instead of the single wildcard, all files are now defined as
<ItemGroup>
<Compile Include="Api\NewClass.cs" />
<Compile Include="Api\SecondClass.cs" />
<Compile Include="Api\ThirdClass.cs" />
...
</ItemGroup>
in the .csproj-file.
If you want to reproduce this yourself
Visit: https://swagger.io/tools/swagger-editor/
Click 'Live Demo'
'Generate Client' > 'csharp'
The step above downloads a zip-file with the VS-solution
Open the solution with VS and add a class
After adding the class you should have the error (unless you used Rider)

Only solution was recreate project :/

Related

How do I prevent text template generator from running on every VS build?

I have a VS 2019 solution with several projects. There is one project that every other project depends on and I have some T4 templates in that project. The templates are regenerated every time I invoke the Build command (no changes) and therefore all the dependent projects are also rebuilt.
How can I fix this so that the templates are only regenerated when necessary? My project file has the following:
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<TransformOutOfDateOnly>true</TransformOutOfDateOnly>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
<ItemGroup>
<None Update="Messages\Messages.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Messages.generated.cs</LastGenOutput>
</None>
<EmbeddedResource Update="Messages\Messages.de.resx" />
<EmbeddedResource Update="Messages\Messages.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Messages.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Target Name="CallTransformOnBuild" BeforeTargets="CoreCompile">
<CallTarget Targets="TransformDuringBuild" />
</Target>
I only want the transform to run on build if:
Messages.Generated.cs doesn't exist
Messages.tt changed
Messages.resx changed
You need to make sure the following XML Tags' are set to false.
<TransformOnBuild>False</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>False</OverwriteReadOnlyOutputFiles>

How to set variables and properties that could be made configurable using the Project Properties' UI in Visual Studio, for a wix setup project?

I am working on WiX Setup V3 project in Visual Studio 2019. I have to make this working in Visual Studio as well as from MSBuild (in Jenkins). I have authored custom target file which will be included in this project. Following is the markup of the custom target file. I cannot use the HeatDirectory task, since it lacks some flags like svb6. Hence I am using Exec command for Heat execution.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefineConstants>HeatFldrPath=$(FilePath);ProductVersion=$(PVersion);BuildNumber=$(BldNum)</DefineConstants>
<OutputName>$(MSIName)</OutputName>
<OutputPath>$(MSIPath)</OutputPath>
<SuppressPdbOutput>True</SuppressPdbOutput>
</PropertyGroup>
<PropertyGroup>
<WixBinPath>$(SolutionDir)\Build\wix\</WixBinPath>
<WixToolPath>$(WixBinPath)\</WixToolPath>
<WixTargetsPath>$(WixToolPath)Wix.targets</WixTargetsPath>
<WixTasksPath>$(WixToolPath)wixtasks.dll</WixTasksPath>
</PropertyGroup>
<ItemGroup>
<WixExtension Include="WixUtilExtension">
<HintPath>lib\WixUtilExtension.dll</HintPath>
<Name>WixUtilExtension</Name>
</WixExtension>
<WixExtension Include="WixUIExtension">
<HintPath>lib\WixUIExtension.dll</HintPath>
<Name>WixUIExtension</Name>
</WixExtension>
<WixExtension Include="WixMsmqExtension">
<HintPath>lib\WixMsmqExtension.dll</HintPath>
<Name>WixMsmqExtension</Name>
</WixExtension>
<WixExtension Include="WixIIsExtension">
<HintPath>lib\WixIIsExtension.dll</HintPath>
<Name>WixIIsExtension</Name>
</WixExtension>
</ItemGroup>
<Target Name="HeatTarget" BeforeTargets="Build">
<Exec Command='"$(WixToolPath)\heat.exe" dir $(HeatFldrPath) -cg UserFeatureFiles -dr APP_DIR -gg -g1 -sfrag -sw -svb6 -srd -sreg -ke -var var.HeatFldrPath -out "Content\UserFiles.wxs"' />
</Target>
</Project>
I need to make this configurable for the following parameters:
Product Version (for use in Candle command)
Build Number (This will be added to the Product Version)
Heat Directory Path
MSI Name (This will have Version along with Build Number concatenated
to it)
MSI Path (I don't want this to be bin\$(Configuration)\en-us, rather
a custom directory I specify)
My custom targets file will be imported to the .wixproj file and nothing else will be changed in the .wixproj file.
If I use DefineConstants in my custom targets file, it works with MSBuild, but not with Visual Studio. I am having a hard time passing these as parameters and getting my MSI to build from both Visual Studio and MSBuild. I tried passing $(FilePath), $(PVersion) and $(BldNum) from project properties, but no luck. I cannot hard code these values in .targets or .wixproj file, since they have to be run from both Visual Studio and MSBuild. Also, I am not able to pass OutputName and OutputPath from Visual Studio. Can anyone please help me?
PFB the wixproj file.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build"
InitialTargets="EnsureWixToolsetInstalled"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == ''
">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.10</ProductVersion>
<ProjectGuid>{9ecbe76b-ecc4-4a17-bc8b-f2224421f616}</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>My.Custom.MSI</OutputName>
<OutputType>Package</OutputType>
<PublishDir>..\HeatFolder</PublishDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug;HeatFldrPath=$(PublishDir)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WixVariables>$(FilePath)=$(ProjectDir)HeatFolder;$(PVersion)="1.1.0.1"
</WixVariables>
<DefineConstants>HeatFldrPath=$(FilePath);ProductVersion=1.1.0.1;BuildNumber=$
(BldNum)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Full-
Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Release;HeatFldrPath=$(PublishDir)</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Content\GlobalCustomActions.wxs" />
<Compile Include="Content\GlobalExitDlg.wxs" />
<Compile Include="Content\GlobalFatalError.wxs" />
<Compile Include="Content\GlobalInstallDlg.wxs" />
<Compile Include="Content\GlobalLicenseAgreementDlg.wxs" />
<Compile Include="Content\GlobalSetupFolderDlg.wxs" />
<Compile Include="Content\GlobalWelcomeDlg.wxs" />
<Compile Include="Content\GlobalWixUI.wxs" />
<Compile Include="Content\Product.wxs" />
<Compile Include="Content\UserFiles.wxs" />
<Compile Include="Content\UserIIS.wxs" />
<Compile Include="Content\UserRegistry.wxs" />
</ItemGroup>
<ItemGroup>
<Folder Include="conf\" />
<Folder Include="Content\" />
<Folder Include="Images\" />
<Folder Include="lib\" />
</ItemGroup>
<ItemGroup>
<Content Include="AppPoolAttrs.xml" />
<Content Include="AppPoolUpgradeChanges.xml" />
<Content Include="conf\default.yml" />
<Content Include="Content\CustomActions.CA.dll" />
<Content Include="Content\GlobalProperties.wxi" />
<Content Include="Content\License.en-us.rtf" />
<Content Include="CustomWix.targets" />
<Content Include="Images\Banner.bmp" />
<Content Include="Images\DEST.ICO" />
<Content Include="Images\dialog.bmp" />
<Content Include="Images\dialog_cust.bmp" />
<Content Include="Images\dialog_template.bmp" />
<Content Include="Images\Exclam.ico" />
<Content Include="Images\folder.ico" />
<Content Include="Images\folderNew.ico" />
<Content Include="Images\New.ico" />
<Content Include="Images\warn.ico" />
<Content Include="lib\WixIIsExtension.dll" />
<Content Include="lib\WixMsmqExtension.dll" />
<Content Include="lib\WixUIExtension.dll" />
<Content Include="lib\WixUtilExtension.dll" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Content\en-us.wxl" />
</ItemGroup>
<Import Project="CustomWiX.Targets"
Condition="Exists('CustomWiX.targets')" />
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)'
!= '' " />
<Import
Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets"
Condition=" '$(WixTargetsPath)' == '' AND
Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets')
" />
<Target Name="EnsureWixToolsetInstalled" Condition="
'$(WixTargetsImported)' != 'true' ">
<Error Text="The WiX Toolset v3.11 (or newer) build tools must be
installed to build this project. To download the WiX Toolset, see
http://wixtoolset.org/releases/" />
</Target>
</Project>
I tried passing $(FilePath), $(PVersion) and $(BldNum) from project
properties, but no luck. I cannot hard code these values in .targets
or .wixproj file, since they have to be run from both Visual Studio
and MSBuild. Also, I am not able to pass OutputName and OutputPath
from Visual Studio.
The main issue is that when you set the variables in Project Properties UI, the values can only pass to the variables in the xxx.wixproj rather than CustomWiX.Targets file.
And this approach is local (modify only the properties of the xxx.wixproj file, which still be overridden by the custom target values).
In more detail, when it reloads the xxxx.wixproj which contains the custom target file, MSBuild will load the xml nodes line by line, since MSBuild properties support forward override values. Simply said, if the same value is defined later, the previous value is overwritten. And the same properties are defined in the custom target file which is imported under the those properties, so the properties in the custom targets file will always override the properties.
Besides, when you pass some variables in the project Properties UI, the values will overwrite the values in the xxx.wixprojrather than custom targets file. And then when you build again, the values in custom targets will still override the values you modified in project properties, so it won't work.
Differ from VS IDE, the msbuild command line can override the value with -p: XXX (property name)= XXXXXX, which is global, so this problem does not occur.
Suggestion
1) If you still want to modify those properties by overriding the value of the project properties, remove the same properties from the custom targets file and move them to wixproj so that they can be used directly.
2) Since the custom target file always overwrites the same properties, you can modify the specific properties directly in the custom target file without having to modify the wixproj file directly.
Update1
The wixvariables(Properties-->Build-->Define Variables) does not work in the xxxx.wixproj file but only for wix file like Product.wxsfile. If you define the property $(Filepath) in the Define Variables, it will never be used for MSBuild. So there is no way to set the properties in Property UI for msbuild Properties.
Besides, $ is used to call a property of MSBuild and MSBuild define a property only under PropertyGroup of xxx.xxxproj like <PropertyGroup><FilePath> xxx</FilePath><\PropertyGroup>.
Solution
You can customize your build by using Directory.Build.targets and remember keeping the name as the document said which is designed by that with the effect. Then you should put this file under the solution folder so that it can work for all the projects.xxx.props file will import on the top of the xxxx.xxproj, so it can not override the values and only the Directory.Build.targets which is imported at the bottom of the xx.xxproj file does.
Then you can define the variables in the file like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<FilePath>xxxxx</FilePath>
</ProperGroup>
.........
</Project>
Hope it could help you.

Publish to Azure doesn't update files in App_Data

My ASP.Net Core app has an App_Data folder located under the project root:
(As I recall -- I may be mistaken -- I had to manually create that folder in the project. The template didn't give it to me automatically.)
My problem is that changes to the files in the App_Data folder are not pushed to Azure when I publish my project. I'm using VS Pro 2019.
When I first published the project, the App_Data folder and its contents were pushed to Azure. But, as I said, changes are ignored.
Here's the larger issue that I don't understand: Apparently, the App_Data folder is special. At least, it's got an entry in the publish profile. And I've seen lots of questions and uninformed answers about difficulties publishing (or not publishing) files that live in this magic folder. But I've never seen anything close to official documentation that talks about this bit of magic.
Here is my publish profile:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<ResourceId>/subscriptions/xxx/resourceGroups/Production/providers/Microsoft.Web/sites/xxx</ResourceId>
<ResourceGroup>Production</ResourceGroup>
<PublishProvider>AzureWebSite</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://xxx.azurewebsites.net</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>xxx</ProjectGuid>
<MSDeployServiceURL>xxx.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>xxx</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>$xxx</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
<InstallAspNetCoreSiteExtension>False</InstallAspNetCoreSiteExtension>
<TargetFramework>netcoreapp2.2</TargetFramework>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>
</PropertyGroup>
</Project>
and here is my project file (edited for brevity):
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<UserSecretsId>aspnet-xxx</UserSecretsId>
<ApplicationInsightsResourceId>/subscriptions/xxx/resourcegroups/xxx/providers/microsoft.insights/components/xxx</ApplicationInsightsResourceId>
<ApplicationInsightsAnnotationResourceId>/subscriptions/xxx/resourcegroups/MyIndigoHealth/providers/microsoft.insights/components/xxx</ApplicationInsightsAnnotationResourceId>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TypeScriptToolsVersion>3.1</TypeScriptToolsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.6.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />
<PackageReference Include="Neleus.DependencyInjection.Extensions" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\Identity\Services\" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
</Project>
According to the official documentation:
The Content item list contains files that are published in addition to
the build outputs. By default, files matching the pattern wwwroot/**
are included in the Content item.
The implication (not clearly stated) is that ONLY build outputs and wwwroot/** are published.
Later in the same documentation, they give examples (without explanation) of markup that adds additional files to the set of files being published. Based on those examples, I cooked up this markup. Adding this to the project (csproj) file causes changed files in the App_Data folder to be published:
<ItemGroup>
<DotnetPublishFiles Include="App_Data/**/*">
<DestinationRelativePath>App_Data/%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</DotnetPublishFiles>
</ItemGroup>
This still leaves a couple of related mysteries:
What does the <ExcludeApp_Data> element really do?
Apparently, the initial Publish (from Visual Studio) pushes the App_Data folder to the server. Why does this happen, when experimentation and the above-referenced documentation says that subsequent attempts to publish ignore the App_Data folder (and, indeed, any folder outside of wwwroot)?
If you right click your web project and select Publish > Settings > File Publish Options, then uncheck "Exclude files from the App_Data folder" what happens?

Include build directory in nuget package using visual studio pack

I'm attempting to create a nupkg with Visual Studio using the built in nuget package building and include the build directory from my project in the nupkg. It seems like it should be a fairly simple task but I can't get it to work. From my googling adding either of these to my csproj file should work, but both create an empty 'build' directory in the nupkg:
<ItemGroup>
<None Include="build\**">
<Pack>true</Pack>
<PackagePath>build\</PackagePath>
<IncludeInPackage>true</IncludeInPackage>
</None>
</ItemGroup>
Using nuget pack to create the package with the following in my nuspec does work:
<files>
<!-- Include everything in \build -->
<file src="build\**" target="build" />
</files>
Include build directory in nuget package using visual studio pack
According to the document Including content in a package, you should use the properties <Pack>true</Pack> and <PackagePath>build\</PackagePath>:
If you want to copy all your content to only a specific root folder(s) (instead of content and contentFiles both), you can use the MSBuild property ContentTargetFolders, which defaults to "content;contentFiles" but can be set to any other folder names.
PackagePath can be a semicolon-delimited set of target paths.
Specifying an empty package path would add the file to the root of the
package.
So, you can change your ItemGroup like following:
<ItemGroup>
<None Include="build\**" Pack="True" PackagePath="build\" />
</ItemGroup>
Update:
I believe this is the same as what I added but in a different XML
structure and without the Pack attribute
The Pack attribute is the key point. It works fine with your XML structure and the Pack attribute. You should make sure you have the files in the build folder in your project folder:
Check my test demo below:
Update2:
Ah! You are using the .net framework project!! That the reason for this issue. This method is used for .net standard and .net core project by default and it not work for .net framework. To resolve this issue you have to use the .nupsec file, like you post in the question.
If you still want to include build directory in nuget package using visual studio pack, you need change your project type to SDK type:
Check this document for some more details.
Then you can use the method, which we talked about before.
Hope this helps.
The solution to this issue was to upgrade the project to SDK type (Xamarin binding projects by default use the old format but seem to work with the new type) and then use:
<ItemGroup>
<None Update="build\**">
<IncludeInPackage>true</IncludeInPackage>
</None>
</ItemGroup>
To include the build directory. The alternative is using nuget pack.
When converting the project make sure to leave in the Xamarin import:
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
Here's how my project file looks afterwards:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<PackageId></PackageId>
<PackageVersion>3.3.2</PackageVersion>
<ReleaseVersion>$(PackageVersion)</ReleaseVersion>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<Authors>Nick Brook</Authors>
<Description></Description>
<Copyright></Copyright>
<PackageProjectUrl></PackageProjectUrl>
<Summary></Summary>
<PackageTags></PackageTags>
<Title></Title>
<PackageReleaseNotes>Initial Release</PackageReleaseNotes>
<OutputType>Library</OutputType>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<OutputPath>bin\$(Configuration)</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<PackageOutputPath>packed</PackageOutputPath>
<PackOnBuild>true</PackOnBuild>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
</ItemGroup>
<ItemGroup>
<ObjcBindingCoreSource Include="Structs.cs" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Structs.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
<Compile Remove="ApiDefinition.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
</ItemGroup>
<ItemGroup>
<None Remove="packed\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Build.Download" Version="0.4.11" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2" />
</ItemGroup>
<ItemGroup>
<None Update="build\**">
<IncludeInPackage>true</IncludeInPackage>
</None>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
</Project>

Wildcard for content in an XNA content project?

I have an XNA 3.1 content project (.contentproj) with the following:
<ItemGroup>
<Compile Include="tiles\B000N800.BMP">
<Name>B000N800</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
<Compile Include="tiles\B000N801.BMP">
<Name>B000N801</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
(... and so on ...)
</ItemGroup>
What I'd like to do is be able to specify a wildcard so that tiles\*.bmp gets compiled instead - so that I don't have to keep re-synchronising the content project when I add and remove textures from the "tiles" directory.
Does anyone know a way to do this?
Ideally the solution would ignore the hidden ".svn" directory, under "tiles". And also the content project would continue to work in Visual Studio.
You'll have to use wildcard in your item definition :
<ItemGroup>
<Compile Include="tiles\**\*.BMP"
Exclude="tiles\.svn\*">
<Name>%(Compile.Filename)</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
I found a blog post by Shawn Hargreaves that describes how to do this for XNA 1.0:
Wildcard content using MSBuild
Based on that, here is what I did which works with XNA 3.1 (and doesn't cause those weird _0 to appear):
Create a separate "tiles.proj" file with the following content:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<ItemGroup>
<WildcardContent Include="tiles\**\*.BMP" Exclude="tiles\.svn\*">
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</WildcardContent>
</ItemGroup>
<Target Name="BeforeBuild">
<CreateItem Include="#(WildcardContent)" AdditionalMetadata="Name=%(FileName)">
<Output TaskParameter="Include" ItemName="Compile" />
</CreateItem>
</Target>
</Project>
And in the original ".contentproj" file, right before </Project>, add:
<Import Project="tiles.proj" />

Resources