Change A File's Build Action Attribute By Team Build 2010 - visual-studio-2010

I have got a project that we publish via ClickOnce; and this project contains some DLL's for localization. But as you know these DLL's are not directly referenced to the project. They are in a separeted folder in the project.
Because of Code Analysis warnings we configured these files' Build Action attribute to None.
But if publish while their Build Action = None, as you guess Visual Studio doesn't include them in to the package. So before we start publish, we change their Build Action attribute to Content.
But now, i want to publish via Team Build 2010; so Team Build will create ClickOnce package. However i couldn't find the way to change Build Action attribute of a file.
Is there any possible way of this?

I found my own solution with using Condition attribute.
The project file contains solution items according to their Build Action property.
For example,
if file's Build Action = None, project file contains it like this
<None Include="MyRequiredAssembly.dll" />
Otherwise, if file's Build Action = Content it looks like this
<Content Include="MyRequiredAssembly.dll" />
All of these files are groupped into <ItemGroup> and ItemGroup tag has Condition attribute.
So i decided to use Condition to change Build Action property like this.
<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Publish|AnyCPU'">
<Content Include="MyRequiredAssembly.dll" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Publish|AnyCPU'">
<None Include="MyRequiredAssembly.dll" />
</ItemGroup>
I hope this helps you too.

Related

Visual studio publish excluding custom dlls from publish directory

I have an Azure function which has an assets folder (needed for something) which contains some files including .pdb, .dll, .exe etc.
When I publish the project using the Visual Studio Publish, it is removing the dlls from that folder.
I've tried adding this to the csproject but still they did not get copied
<ItemGroup>
<Content Include="assets\**\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</Content>
</ItemGroup>
Tried doing a post build copy event as well but that didn't work either
xcopy "$(ProjectDir)assets\*.*" "$(TargetDir)\assets" /Y /I /E
The left image contains the structure of the folders and the dlls that the solution has but when the publish happens I don't see the dlls in the published folder.
How do I get all the files/folders in the assets folder to be copied to the publish folder?
Instead of post build event, try using your own MSBuild targets.
We must extend a target called CopyAllFilesToSingleFolder. PipelinePreDeployCopyAllFilesToOneFolderDependsOn is a dependence property of this target that we can use to inject our own target into. In order to inject CustomCollectFiles into the process, we will first create the target.
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="..\Extra Files\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
Create the item _CustomFiles and instruct it to pick up every file in that folder and any folders below it in the Include attribute. The FilesForPackagingFromProject item is then filled out using this item. In order to add additional files, MSDeploy actually uses this item. Also take note of the metadata DestinationRelativePath value I declared. This will determine where it will be located within the package relative to other objects. Extra Files%(RecursiveDir)%(Filename)%(Extension) is the statement I used in this instance. It should be put in the same relative spot in the package where it is in the Extra Files folder, according to what that means.
Please refer this SO Thread for more information.

Different/Multiple Package.appxmanifest File depending Upon different Configuration UWP

I have a Xamarin Project and have different configuration depending upon the type of release. I want to point to different Package.appxmanifest Depending upon my configuration. How can I achieve that.
Different/Multiple Package.appxmanifest File depending Upon different Configuration UWP
If you do want to use different Package.appxmanifest files for some build configurations. you could edit yourproject.csproj manually.
Right Click Project-> Unload Project-> Re-Right Click Project-> Edit Project.csproj file.
<ItemGroup>
<None Include="xxxxx_TemporaryKey.pfx" />
<AppxManifest Include="Test.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
Find out the above ItemGroup node and reserve only one AppxManifest. And then modify the follow PropertyGroup node.
<PropertyGroup>
<ApplicationManifest>Test.appxmanifest</ApplicationManifest>
</PropertyGroup>
For more please refer this case reply.

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.

Xamarin: Different appxmanifest files for different build configurations

I want to use different Package.appxmanifest files for some build configurations. I cannot include more than one appxmanifest-file into my Xamarin-UWP project.
And ideas like doing it like Android also doesn't work:
Working for multiple AndroidManifest files:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release-CH|AnyCPU'">
…
<AndroidManifest>Properties\AndroidManifestCH.xml</AndroidManifest>
</PropertyGroup>
How can I achive this for UWP?
And ideas like doing it like Android also doesn't work
According to App package manifest, Every app package must include one package manifest. If you create a new appxmanifest file in the uwp, it will throw error like the follow.
The project contains 2 items that represent the app manifest: Package.appxmanifest, Test.appxmanifest. The project can contain only one app manifest
If you do want to use different Package.appxmanifest files for some build configurations. you could edit FileGuidTest.csproj manually.
Right Click Project-> Unload Project-> Re-Right Click Project-> Edit Project.csproj file.
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<AppxManifest Include="app.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<None Include="FileGuidTest_TemporaryKey.pfx" />
<AppxManifest Include="Test.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
Find out the above ItemGroup node and reserve only one AppxManifest. And then modify the follow PropertyGroup node.
<PropertyGroup>
<ApplicationManifest>Package.appxmanifest</ApplicationManifest>
</PropertyGroup>

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.

Resources