I am using visual studio 2012 and I am finding it difficult to add web.config files for diff environment. I looked at this link and tried right clicking on .pubxml file and choose add config transform option. After I do this, system adds web.simplePublish.config file which I am not able to rename using visual studio.
If I rename the file using windows explorer, the file is not listed under web.config tree in the solution.
What is the right way to add web.config files for various environments in Visual Studio 2012.
you can try to modify the *.csproj then find out the filename before you rename it and to revise the filename that you using windows explorer.
or you can just try to add a new tag into *.csproj
<ItemGroup>
<Content Include="..\default.licenseheader">
<Link>default.licenseheader</Link>
</Content>
<Content Include="packages.config" />
<None Include="Properties\PublishProfiles\xxxx.pubxml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.SimplePublish.config">
<DependentUpon>Web.config</DependentUpon>
</None>
The other way that you can use Configuration Manager at your visual studio please refer the following link Add an Additional
I used SlowCheetah - XML Transforms plugin of visual studio to create web.config files for diff environment.
Related
I'm facing a strange issue I have created a brand new xamarin forms project and i'm trying to adding Resource file in the shared project but when i add the Resource file then .resx extenshion file is created Like AppResources.resx creates but the code behind like AppResource.designer.cs not creating
Things that i have tried.
I have try multiple time and clean rebuild the project.
Create new project and try to again add resource file.
use custom tool to build the resource.
To manually fix the csproj, so it generates AppResources.designer.cs from AppResources.resx, follow these steps:
Close Solution (or quit Visual Studio).
Open YourProject.csproj in any text editor.
Find all lines that refer to AppResources.designer.cs or AppResources.resx.
Add or change as needed, to be similar to this (from https://github.com/xamarin/xamarin-forms-samples/blob/main/UsingResxLocalization/UsingResxLocalization/UsingResxLocalization/UsingResxLocalization.csproj):
<ItemGroup>
<Compile Update="Resx\AppResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AppResources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resx\AppResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>AppResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
Save the csproj file.
Open your solution.
In my CSPROJ I have a subfolder ›None‹. It is setup like this:
<ItemGroup Label="None">
<Compile Remove="None/**/*.cs" />
<None Include="None/**/*.cs" />
</ItemGroup>
In there I have CS files, that I don't want to compile.
No, I want to move a file (lets say ›CompileIt.cs‹ from ›None‹ back to the project, because now I want to compile it again.
If I move it outside of Visual Studio (like directly in the explorer or via PowerShell) it does exactly what I want, the file is now in a different folder inside the project and the Build-Action changes from ›None‹ to ›C# Compiler‹.
But if I move the file in Visual Studio, something different happens. Visual Studio changes the CSPROJ file like this:
<ItemGroup Label="None">
<Compile Remove="None/**/*.cs" />
<None Include="None/**/*.cs" />
</ItemGroup>
<ItemGroup>
<None Include="CompileIt.cs" />
</ItemGroup>
Now I have to either delete the ItemGroup from the CSPROJ again or change the "Build Action" in the Solution Explorer`s Properties page of the file.
Of course I know, this is usually exactly what you would expect, because normally a build action shouldn't change if you only move the file.
But anyway, is there a way to let Visual Studio know to not change CPSROJ file if I move a file inside it?
Or alternatively, is there a way to mark a subfolder in Visual Studio so that Visual Studios knows it should ignore all files in it?
PS: Oh, I forgot to say this, it is a Core-Style CSPROJ file, that means, all CS files are included automatically.
In our project there are some front-end developers that use a different IDE from VS to write JS, CSS and HTML templates. However our build process does not include the files in their appropriate folders, but only the ones that are specified in the .csproj files.
Front-end developers should be able to edit their files in the separate IDEs and before they commit to source control they would build the VS Solution once. I want their files to be included in the .csproj file of the project on build.
You can include files to project by mask, so front-end developers can build solution with these files from command line.
For example:
<ItemGroup>
<Content Include="..\..\Client\*.css">
<Link>%(Filename)%(Extension)</Link>
<!-- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> -->
</Content>
<Content Include="..\..\..\..\Bin\Client\Drivers\**\*.*">
<Link>Drivers\%(RecursiveDir)%(Filename)%(Extension)</Link>
<!-- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> -->
</Content>
</ItemGroup>
I am working in the new Visual Studio 2010 RTM and I would like to use web.config transforms.
My site is configured to use .NET 4.0 but it was formerly a Visual Studio 2008 web application project.
When I right-click on my web.config file I do not see the 'Add Config Transforms' option as I should. I also tried adding creating a new web.config but I still do not see the transform option.
Does anyone know how to enable web.config transforms for projects in Visual Studio 2010 that were originally created in Visual Studio 2008?
I was able to get this to work with my existing project.
I did it by opening my csproj file in notepad and comparing the child elements to those of a brand new ASP.NET MVC project for VS2010.
I then removed several elements that I didn't need and saved and reloaded my project. Then I was able to select 'Add Config Transforms.'
I do not know exactly which element was the culprit but I would guess it was either <ProductVersion>9.0.30729</ProductVersion> or <OldToolsVersion>3.5</OldToolsVersion</>.
I was able to get this to work in my converted project by opening up the .proj file and adding the following:
<ItemGroup>
<Content Include="Web.Staging.config">
<DependentUpon>Web.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
</ItemGroup>
Then I copied my existing web.config twice into the web root and renamed them Web.Release.config and Web.Staging.config
In VS I right mouse clicked and included them in the project
I then opened them up and added
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
to the configuration node so it looked like:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
You have to have matching Release and Staging configuration names (using configuration manager).
After this VS recognised them as web configuration transformation files
I am using
<ItemGroup>
<EmbeddedResource Include="..\..\resources\hbm\*.hbm.xml" />
</ItemGroup>
to include a bunch of xml files into my C# project. Works fine.
But, I don't want them in the "root level" of my project, I would rather see them in a subfolder in my project.
For example, this file is included into a Mapping folder in Visual Studio:
<ItemGroup>
<EmbeddedResource Include="Mapping\User.hbm.xml" />
</ItemGroup>
That's what I want for my *.hbm.xml files.
I can't figure out how to do it and still keep my wildcard *.hbm.xml part and also keep the actual files in a different directory.
I've looked at MSDN's doc on MSBUILD and items, but no luck.
Perhaps this has changed in MSBuild since the original answer was posted, but it is possible to use both wildcards and links at the same time. For example, I use the following block in a C# project to import data files into a test library.
<ItemGroup>
<None Include="..\SOMENAME.Tests\data\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>data\%(RecursiveDir)%(Filename)%(Extension)</Link>
</None>
</ItemGroup>
The only disadvantage I've seen so far is that MSBuild recreates the folder names on the file system (ie $(ProjectPath)\data\somesubfolder) which is a little annoying but not a huge issue.
As a test, I also tried the OP's request of embedding resources, using the following snippet, and again this seemed to work fine - dotPeek showed the resources were present in the compiled assembly in addition to being present in the Solution Explorer.
<ItemGroup>
<EmbeddedResource Include="..\SOMENAME.Tests\data\**\*.*">
<Link>resources\%(RecursiveDir)%(Filename)%(Extension)</Link>
</EmbeddedResource>
</ItemGroup>
(This was using Visual Studio 2013 and still works as of VS2019)
Update 08Jun2021: The above syntax works is fine for old style csproj files, but if you are using the new SDK format, the syntax is a little different, albeit simpler.
The OP's original question of wildcard embedding can be accomplished with the following
<ItemGroup>
<EmbeddedResource Include="data\**\*.*" />
</ItemGroup>
And to have wildcard file copies for changed or missing files.
<ItemGroup>
<None Update="data\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
I think you can't use links and wildcard at the same time.
You could use this notation to link to include User.hbm.xml file in Mapping folder in Visual Studio :
<ItemGroup>
<EmbeddedResource Include="..\..\resources\hbm\User.hbm.xml">
<Link>Mapping\User.hbm.xml</Link>
</EmbeddedResource>
</ItemGroup>
But you can't do that
<ItemGroup>
<EmbeddedResource Include="..\..\resources\hbm\**\*.hbm.xml">
<Link>%(RecursiveDir)\%(Filename)%(Extension)</Link>
</EmbeddedResource>
</ItemGroup>
I have been able to create the logical name based on some regex (for only one folder depth). The root namespace I want is Agility.BmsData.Create and and example of the final name of the resource could be Agility.BmsData.Create.tables.mytable.sql where the file is in a folder tables\mytable.sql
<ItemGroup>
<EmbeddedResource Include="..\..\AgilityDatabase\Create\**\*.sql" >
<!-- see https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-well-known-item-metadata?view=vs-2022 -->
<!-- https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2022 -->
<LogicalName>
Agility.BmsData.Create.$(
[System.Text.RegularExpressions.Regex]::Match("%(Directory)", "(?<=\\)[^\\]+(?=[\\]*$)")
).%(Filename)%(Extension)
</LogicalName>
</EmbeddedResource>
</ItemGroup>
It is also possible to customise the Link attribute of the EmbeddedResource element but the value needs to be suitably encoded for embedding in an xml attribute.
Following on from the above example, I have sql files located in the database project on a relative path to the current project of ..\..\AgilityDatabase\Create\ and I want to mimic the file structure (and resource names) in my other project. I can use the following MsBuild command $([System.Text.RegularExpressions.Regex]::Match("%(Directory)", "(?<=\\AgilityDatabase\\Create\\).+$"))\%(Filename)%(Extension)
So my Item group becomes:
<EmbeddedResource Include="..\..\AgilityDatabase\Create\**\*.sql"
Link="Create\$([System.Text.RegularExpressions.Regex]::Match("%(Directory)", "(?<=\\AgilityDatabase\\Create\\).+$"))\%(Filename)%(Extension)">
</EmbeddedResource>