Where is Visual Studio Build Action stored? - visual-studio

I'm writing a parser to pull data from various programs.
Some of the programs have "Build Action" set to "None" and I want to skip them.
I was guessing that this property would be in the .csproj, .btproj file, but I don't see it there. So my question is where is it stored?
I'm specifically dealing with BizTalk orchestrations, but I think the same concept would apply to C# and C# project files as well. I'm using Visual Studio 2015 to be compatible with BizTalk 2016.

It seems to create a "None" XML element in the .btproj file as shown below.
I was expecting to be an attribute or element value, not an xml element itself.
<ItemGroup>
<None Include="Orchestrations\PublishPIHistoricalData_v2.odx">
<SubType>Task</SubType>
<TypeName>PublishPIHistoricalData_v2</TypeName>
<Namespace>ABC.Integration.BizTalk.ProcessDataHistorian.Orchestrations</Namespace>
</None>
whereas a compiled orchestration will look like this:
<ItemGroup>
<XLang Include="Orchestrations\PublishPIDataODS.odx">
<SubType>Task</SubType>
<TypeName>PublishPIData_ODS</TypeName>
<Namespace>ABC.Integration.BizTalk.ProcessDataHistorian.Orchestrations</Namespace>
</XLang>

Related

How to apply nested files in Visual Studio 2019 for Class Library project

Microsoft Visual Studio Community 2019.
Version 16.9.5.
I want *.Generated.cs files to be nested under corresponding *.cs file in a Class Library project exactly like in does in a RestApi Console Application project.
File nesting is enabled for both projects, Active Settings is set to 'Web' for both.
Using Visual Studio 2019 (16.10.3) here. Based on the recommendation of another answer I got it to work by putting the following in the .csproj file, then reopening the solution. I don't know if it matters or not, but I put this as the last elements group the closing </Project> tag in the file.
<ItemGroup>
<ProjectCapability Include="DynamicDependentFile" />
<ProjectCapability Include="DynamicFileNesting" />
</ItemGroup>

How can I get VS to consider my project dirty when (only) an .exe Content item is dirty?

My C++ project includes a set of (non-code) files that need to be copied to the output directory verbatim. I added them to my .vcxproj as Content nodes with CopyToOutputDirectory set to PreserveNewest. For example:
<ItemGroup>
<Content Include="util.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="lib_util_needs.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<!-- etc. -->
</ItemGroup>
This almost works; when I build the project, each content file is correctly copied to the output directory if its timestamp is newer than whatever's already there. But... if I update one of these content files without modifying an actual compiled code file at the same time, Visual Studio 2017 concludes that the project is already up to date, does not build, and does not copy the newer version of the content file to the output directory. Is there anything I can do about this? Things that do not work:
Setting PublishState to Prerequisite under the Content node
Listing content files as DependentUpon nodes under a code file's node
Edit: After further investigation, it appears that the behavior depends on the content file's extension. For example, dlls behave the way I want (project marked as dirty and built if the timestamp is updated), but exes do not.
How can I get VS to consider my project dirty when (only) a Content item is dirty?
You can set the property the UpToDateCheckInput to the item:
<ItemGroup>
<UpToDateCheckInput Include="util.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</UpToDateCheckInput>
<!-- etc. -->
</ItemGroup>
Or set the property DisableFastUpToDateCheck to true in the project file to disable FastUpToDateCheck for Visual Studio build manager:
<PropertyGroup>
<DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
</PropertyGroup>
Check MSDN about DisableFastUpToDateCheck:
A boolean value that applies to Visual Studio only. The Visual Studio
build manager uses a process called FastUpToDateCheck to determine
whether a project must be rebuilt to be up to date. This process is
faster than using MSBuild to determine this. Setting the
DisableFastUpToDateCheck property to true lets you bypass the Visual
Studio build manager and force it to use MSBuild to determine whether
the project is up to date
Hope this helps.

Preventing Visual Studio from rewriting project references

I have a large solution in which the "root" project includes feature projects by glob:
<ProjectReference Include="..\Feature\*\*.csproj" />
This works, despite not looking great in the references list, but the issue that occasionally Visual Studio will rewrite the csproj with all of the project references resolved:
<ProjectReference Include="..\Feature\A\A.csproj" />
<ProjectReference Include="..\Feature\B\B.csproj" />
It's not clear what triggers this, but I'm guessing it might have something to do with NuGet.
Is there anyway to stop VS from doing this (akin to using DisableFastUpToDateCheck for custom MSBuild scenarios)?
It's not clear what triggers this, but I'm guessing it might have something to do with NuGet.
It should be related to the items in the ItemGroup. I have the similar issue before, but the difference is that I use wildcards to contain .cs files and your are .csproj files, looks like:
<ItemGroup>
<Compile Include="**\*.cs" />
</ItemGroup>
When I delete one of .cs file in the <ItemGroup>, the wildcard gets expanded in the csproj file. For you case, if I deleted the the C.csproj project from Visual Studio (Add it before, reload the root project), then I got the same result as you.
For this issue, many other community members submit a user voice to Visual Studio team: VS IDE should support file patterns in project files. Now this is well supported in the new project system used by .NET Core and .NET Standard in Visual Studio 2017, but they haven't done the work to support it for existing project types.
Is there anyway to stop VS from doing this (akin to using DisableFastUpToDateCheck for custom MSBuild scenarios)?
To resolve this issue, you can use option Exclude="..." to exclude the project that you do not want to refer to:
<ItemGroup>
<ProjectReference Include="..\Feature\*\*.csproj" Exclude="..\Feature\C\C.csproj" />
</ItemGroup>
Or, if you want to delete one of project and keep the wildcard pattern, you only need to unload the root project, then delete the reference project, reload the root project, the wildcard pattern would be preserved.
Hope this helps.
I've done further research on this.
For testing, you can consistency reproduce the expansion by renaming any project that's included in the wildcard pattern.
Also, the easiest way to prevent the expansion is to:
Move the project reference globs into Directory.Build.props or another external file
Set DisableFastUpToDateCheck to true in your csproj
Using properties doesn't work and isn't required, likewise with using an Exclude.

Get files hidden in msbuild from Visual Studio?

A file can be hidden from Visual Studio using the "Visible" metadata, e.g.
<Compile Include="Hidden.cs">
<Visible>false</Visible>
</Compile>
The file is still built as part of the project, but isn't displayed in Visual Studio - it's not included in the hierarchy information.
Is it possible to get at this file programmatically, in Visual Studio? E.g. by getting access to the msbuild object model and getting all Items with the Visible metadata set?
The following target lists hidden files:
<Target Name="ShowHiddenFiles">
<Message Text="'%(Compile.FullPath)'" Condition="%(Compile.Visible) == false" />
</Target>
I don't know if there's a better way to get the msbuild object model from a VS project, but I can get all of the currently loaded projects from an msbuild static property:
Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection
And then I can call GetLoadedProjects(path) passing in the path of the project I'm trying to get. From there I can interrogate the returned Project object to get at the items.

How to export and import an XSD file in Visual Studio?

How do i export and import an XSD in visual studio? I simply tried to do a copy-and-paste an xsd file into a new project and VS2008 automatically created some wrapper classes for it. When i tried to add a query to a table in VS, I get an error that the connection strings are broken. I slightly fixed that by inserting the proper connection string to app.config but i still get errors related to the connection string.
My question is not how to fix this connection string but how do i just properly export and import connection string? is there a wizard I can use? Thanks
Update #2
This XSD file that I'm using was created by using VS studio by dragging and dropping tables using this tutorial http://www.asp.net/learn/data-access/tutorial-01-cs.aspx. I copied this XSD file and pasted it into a new project and VS automatically generated code for it, which in this case a "typed dataset". In this new project, when i tried to add a query to a table in the XSD file (using the tutorial I mentioned before), I got an error stating that the connection string 'xxxxxxxxx' does not exist (im paraphrasing). This 'xxxxxxxxx' connection string exists only in the project where i copied the XSD file from and not in the new project. Therefore, this xsd contains information dependent on the web.config, specifically it's connection strings. So coping and pasting this XSD file does not work. I was hoping there was a wizard export tool that would strip away the depending information (ie: connection string) and its associated settings so that i could properly add it to another project and add a query to a table without errors. I hope that makes sense...
This does not work. The problem is that adding an existing dataset to a project only adds it as an xsd i.e. Visual Studio is thinking xml schema not dataset. This is true even in VS 2015. In order to make this work, after you add the existing xsd file you must edit the project file with gvim or notepad and add the following lines:
Add in the compile section:
<Compile Include="MyDataSet.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>MyDataSet.xsd</DependentUpon>
</Compile>
Look for the ItemGroup tag that has
<None Include="MyDataSet.xsd"/>
Change that line to look like the following and add a couple more Done tabs just so:
<None Include="MyDataSet.xsd">
<Generator>MSDataSetGenerator</Generator>
<LastGenOutput>MyDataSet.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</None>
<None Include="MyDataSet.xss">
<DependentUpon>MyDataSet.xsd</DependentUpon>
</None>
<None Include="MyDataSet.xsc">
<DependentUpon>MyDataSet.xsd</DependentUpon>
</None>
Save the file and reload the Visual Studio project. You are almost done. Right click on the xsd file and select run custom tool. Now you can build and you should be ok.
What do you want to do with your XSD??
By default, Visual Studio will created a "typed dataset" based on your XSD. You can use that to query your database table and update it if needed. Is that what you want?
If not: what do you want to do with your XSD inside Visual Studio then??
You can easily just add an existing XSD on disk to your Visual Studio project by doing a "Add Existing Item" and then picking that file. There's no separate "import / export" functionality, really.
If you only want to use your XSD for documentation / information purposes, click on the file and in its properties window, set its "Build Action" to "None" or "Embedded Resource".
Marc

Resources