Our solution contains ~50 projects. They all import a custom .target file that sets the OutDir variable so that all projects build to a common Binaries folder.
Problem is: MSBuild does not check the OutDir folder for the .dlls but keeps looking inside the OutputPath folder (e.g. bin\Debug). As the OutputPath folder is empty it states that each project is not up-to-date and forces a rebuild. This is not an issue on our TFS build agents but it drastically increases the time between hitting F5 and the application starting on our development machines. Debugging becomes quite a pain.
From the Binaries folder we copy the .dlls to our applications folder structure which we use for generating setups etc. Thus simply dropping the use of OutDir in favor of various OutputPaths is not an option.
Is there any way to tell MSBuild to also check the OutDir folder when looking for existing .dlls?
Following import in csproj files works for me in VS 2015. I added comments about which settings make it fail:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<!-- to distinguish by $(Platform) does not work, a rebuild is triggered since the up-to-date check fails -->
<!-- if IntermediateOutputPath is not set here at all, it does not work either, i.e. it always rebuilds -->
<IntermediateOutputPath>$(SolutionDir)obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>
<UseCommonOutputDirectory>False</UseCommonOutputDirectory>
<DisableFastUpToDateCheck>false</DisableFastUpToDateCheck>
</PropertyGroup>
<PropertyGroup Condition=" '$(OutputType)' == 'Library' ">
<!-- To distinguish by \lib\ does not work, a rebuild is triggered since the up-to-date check fails -->
<!-- <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\lib\</OutputPath> -->
<OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)</OutputPath>
<OutDir>$(OutputPath)</OutDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(OutputType)' == 'Exe' ">
<OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\</OutputPath>
<OutDir>$(OutputPath)</OutDir>
</PropertyGroup>
</Project>
The file is included in csproj files just before Import Microsoft.CSharp.targets:
.csproj file:
<!-- position of include is important, OutputType of project must be defined already -->
<Import Project="$(SolutionDir)ComponentBuild.props" Condition="Exists('$(SolutionDir)ComponentBuild.props')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
Also see my own SO question about it:
MSBuild, OutputPath to a lib directory is not honoured
Related
We have a number of Xamarin iOS projects that are part of our main solution since we need to ensure that they compile as part of the gated check-in. However most of our developers are not using iOS and hence do not configure a connection to a Mac build agent.
During build locally and on our servers, we see this warning:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(63,5): Warning VSX1000: No Address and User has been specified in order to establish a connection to a Mac Server, so only the main assembly was compiled for project 'MyProject.iOS'. Connect to a Mac Server and try again to build the full application.
Is there some way of configuring whether this should be a warning, so that we can remove it from the Error List in Visual Studio and the build log from the server? Preferably it should be done in the projects so it could be set once for everyone.
We are using latest Visual Studio 2017 and TFS 2017 Update 2 and build vNext.
A dirty workaround is to override the targets that produce the warning - in my case that's fine as I don't need them.
In our iOS project files I conditionally (if a server address is defined) import a target file, AvoidMacBuildWarning.target, that replaces a number of targets.
Parts of the project file:
...
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets"/>
<Import Project="AvoidMacBuildWarning.target" Condition=" '$(ServerAddress)' == '' " />
<ItemGroup>
...
AvoidMacBuildWarning.target:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="_SayHello">
<Message Text="Warning (demoted to message) VSX1000: No Address and User has been specified in order to establish a connection to a Mac Server, so only the main assembly was compiled for project 'MediumService.iOS'. Connect to a Mac Server and try again to build the full application." />
</Target>
<Target Name="_SayGoodbye">
</Target>
<Target Name="_DetectSdkLocations">
</Target>
<Target Name="_CollectBundleResources">
</Target>
<Target Name="_PackLibraryResources">
</Target>
<Target Name="CopyFilesToMacOutputDirectory">
</Target>
</Project>
We do nothing special to change the warning behavior in VSTS/TFS build comparing with local build through visual studio.
As far as I known, suppressing warnings with MSB prefix is still not possible. Refer to: Supress/Disable/Solve Visual Studio Build Warning
You could give a try with /property:WarningLevel=0through MSBuild argument. Not sure if it will work with this kind of warning above. If not, afraid there is no way to bypass it.
You should use /nowarn:VSX1000 per msbuild documentation
I'd like to add a small variation of Tore Østergaard's answer in case you converted your CSPROJ to an SDK-style project (which iOS projects at this time are usually not, but you can make it work).
In an SDK-style project the "system" targets and props are imported via an SDK attribute at the top of the CSPROJ, like this:
<Project Sdk="MSBuild.Sdk.Extras">
... various project settings ...
</Project>
But if you try to use Tore Østergaard's answer, it won't work, because that answer's target overrides will be themselves overwritten by the SDK's targets (which are always imported last).
The workaround is to manually import the SDK targets and props so that you can control their order:
<Project>
<!--
The SDK is imported manually so that certain targets can be overridden (see bottom of file).
Otherwise we could use Project Sdk="MSBuild.Sdk.Extras"
-->
<Import Project="Sdk.props" Sdk="MSBuild.Sdk.Extras" />
... various project settings ...
<!-- See comment at top of file about manually importing SDK -->
<Import Project="Sdk.targets" Sdk="MSBuild.Sdk.Extras" />
<!--
These targets must be imported last so that they override the SDK-provided targets.
These override the Mac build agent command because they are not needed on CI.
-->
<Import Project="AvoidMacBuildWarning.targets" Condition=" '$(SkipMacBuild)' == 'true' " />
</Project>
Note: I also changed the condition to be a specific condition SkipMacBuild, but you can use whatever condition you want that makes sense for your build.
I also had to add an additional "empty target" to AvoidMacBuildWarning.targets to ensure they were also quieted. My full AvoidMacBuildWarning.targets looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Inspired by https://stackoverflow.com/a/47182083 from Tore Østergaard -->
<Target Name="_SayHello">
<Message Text="INFO: This would have been MSBuild warning VSX1000, but it has been ignored by importing this targets file." />
</Target>
<Target Name="_SayGoodbye">
</Target>
<Target Name="_DetectSdkLocations">
</Target>
<Target Name="_CollectBundleResources">
</Target>
<Target Name="_PackLibraryResources">
</Target>
<Target Name="CopyFilesToMacOutputDirectory">
</Target>
<Target Name="_VerifyBuildSignature">
</Target>
<Target Name="_VerifyXcodeVersion">
</Target>
</Project>
I have some xaps being built by other projects in my solution and I need the xaps to be included in the resulting WSP.
I have a mapped folder Layouts with a sub-folder ClientBin and then in the csproj I have the following:
<ItemGroup>
...
<Folder Include="Layouts\ClientBin\" />
...
<Content Include="Layouts\ClientBin\*.xap" />
</ItemGroup>
...
<Target Name="BeforeLayout">
<ItemGroup>
<XAPFiles Include="..\..\out\$(Configuration)\bin\sl\xap\**\*.xap" />
</ItemGroup>
<Copy SourceFiles="#(XAPFiles)" DestinationFolder="Layouts\ClientBin" OverwriteReadOnlyFiles="true" />
</Target>
When I delete the xaps from the destination folder and open the SP project in VS the package manager shows the layouts folder with nothing in it. And then when I build none of the xaps get packaged in the WSP but the copy operation worked local to the project. If I rebuild nothing changes. If I unload and reload the project then build, the WSP does contain the files I need.
This works for my dev box because I can make sure I'm performing all these steps to keep the package manager happy, but it doesn't work on the team build machine. Are there steps I can take to make sure the package manager grabs those xaps or even other ways to achieve what I'm trying to do?
I created empty placeholders in Layouts\ClientBin for all the xaps to be copied.
This wasn't optimal since it required some manual dependency management, but it works.
The end result is that the package manager is aware of those files existing when you open the project in VS and that they need to be packaged up into the WSP. The copy operation works as before but now the new files are packaged.
I'm hoping to stop including the generated JavaScript files in TFS source control, but I haven't managed to get the compiler to run on a build.
I've followed this chap's example and edited the project file to give me:
<ItemGroup>
<TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
</ItemGroup>
<Target Name="BeforeBuild">
<Message Text="Before Build" Importance="high" />
<CallTarget Targets="TypeScriptBuild"/>
</Target>
<Target Name="TypeScriptBuild" Inputs="#(TypeScriptCompile)" Outputs="%(Identity).Dummy" Condition="'$(CompileTypeScript)'=='true'">
<Message Text="Building typescript file - #(TypeScriptCompile)" Importance="high" />
<Exec Command=""$(MSBuildProgramFiles32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\tsc" -target ES3 "#(TypeScriptCompile)"" />
</Target>
I've changed the file location where the tsc executable is and removed the TypeScript version information, but it isn't doing anything for me. I'm a complete newbie at this build stuff so would appreciate any help, or tips on how to debug it.
Edit 1
Removed
<ItemGroup>
<TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
</ItemGroup>
as it was redundant - this is added individually for every TypeScript file in the project.
The only warnings I'm getting are about inconclusive unit tests. I assumed that <Message Text="Before Build" Importance="high" /> would produce some kind of log message but I can't see it anywhere.
Edit 2
Got it working locally within Visual Studio by putting
<Target Name="BeforeBuild">
<Message Text="Compiling typescript...">
</Message>
<Exec Command=""$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript\tsc" -target ES3 #(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
at the end of the .csproj file. For some reason this doesn't work when TFS is building it. If I change the TypeScript compiler file location to something nonsensical it complains, but when it's correct there are no JavaScript files produced.
You really shouldn't have to do any of this. Make sure this line is in your csproj, before the </project>
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
Then install TypeScript on the build machine. Also you need to make sure the Build Action of the .ts files is set to TypeScriptCompile. At this point, TypeScript will compile your .ts files and generate the js files. You won't (and shouldn't) check the .js files into your code repository.
Unit Tests
You really want your unit tests building with the rest of your code. Even more, you can run these unit tests at build time and use them to fail the build if any of those tests fail!
Check out this post on msdn and this post on codeplex to help get you started. It will involve using Chutzpah. Also, be aware that the way your .js bundling / delivery may be different when using Chutzpah, since Chutzpah will have to build that bundle for you and I'm not sure how your actual site is doing it.
I've completed rewritting my javascript framework project in TypeScript. Now I'm trying to use these files in many other web projects.
I've tried linking (Linked File) them into the web project. First thing I noticed, I can't change the Build Action to "TypeScriptCompile". .ts files are compiled in their source folder, not where they are linked. The problem is that when creating a new file .ts file in web project, it doesn't see the linked files and I get a TypeScript error.
Also, everytime I try to build a project with Linked TypeScript Files, it crashes Visual Studio.
I'm using AMD and RequireJS. The structure needs to be respected. I'm setting the baseURL to /Scripts/ and my framework and TS files need to be inside that structure.
Does anyone have any idea ?
Here's a sample of what I'm trying
Content from Linked File from a Framework project:
export class Log {
static error (msg: string) { console.log(msg); }
}
Content from File in web project using Linked File:
import fw = module('linkedFile');
fw.Log.error('this file can\'t find the linked file, so this code won\t work');
Thanks !
UPDATE:
The only way I found so far is to copy Frameworks files from the source project to my web project on Post Build:
xcopy /y /e /s /d "$(ProjectDir)Scripts\." "$(ProjectDir)..\..\OtherProject\Scripts\."
The problem with this is we have to edit framework files in the first project, otherwise, our changes will be overwritten.
UPDATE 2:
I'm currently using this script to automatically copy all linked files where they are in the project. You need to edit your CSPROJ file and it has to be a WEB Project. Check the link for a complete description:
http://consultingblogs.emc.com/jamesdawson/archive/2008/06/03/using-linked-files-with-web-application-projects.aspx?CommentPosted=true#commentmessage
<!-- ======================== -->
<!-- Copy linked files -->
<Target Name="_CopyLinkedContentFiles">
<!-- Remove any old copies of the files -->
<Delete Condition=" '%(Content.Link)' != '' AND Exists('$(WebProjectOutputDir)\%(Content.Link)') " Files="$(WebProjectOutputDir)\%(Content.Link)" />
<!-- Copy linked content files recursively to the project folder -->
<Copy Condition=" '%(Content.Link)' != '' " SourceFiles="%(Content.Identity)" DestinationFiles="$(WebProjectOutputDir)\%(Content.Link)" />
</Target>
<!-- Override the default target dependencies to -->
<!-- include the new _CopyLinkedContentFiles target. -->
<PropertyGroup>
<PrepareForRunDependsOn>
$(PrepareForRunDependsOn);
_CopyWebApplication;
_CopyLinkedContentFiles;
_BuiltWebOutputGroupOutput
</PrepareForRunDependsOn>
</PropertyGroup>
<PropertyGroup>
<!-- <PostBuildEvent>$(MSBuildBinPath)\msbuild.exe "$(ProjectDir)_build\site.xml"</PostBuildEvent> -->
</PropertyGroup>
<!-- ======================== -->
When you link a file the path is still relative to its actual location, so you'd have to use a whole bunch of ../../../ to get there.
One option is to set the file to copy on build so it will be copied to your bin folder. I do this for tests but not for releasable code.
Another option is to package your modules to make it easier to use particular versions. You could use a private NuGet repo to do this.
I am trying to do a Jenkins-based automated build/deployment of a web application (.NET 4.0). The web application project has several project references, which in turn have binary references third party DLLs.
The problem:
The second-level references (references of project references) are not pulled into the bin folder in the obj\<CONFIGURATION>\Package\PackageTmp\bin folder, used for building deployment packages.
When I build in the visual studio, the second level references are pulled into the regular build output directory.
When building with MSBuild, second level dependencies are not pulled into the regular output directory, nor into the PackageTmp\bin directory.
This is confirmed by MS as a Won't-Fix issue here.
Related questions here, here and here either do not match my problem, or offer solutions that don't work. I've reviewed all answers, not just the accepted ones.
My build command looks like this (using MSBuild 4.0):
MSBuild MySolution.sln /p:Configuration=Integration /p:platform="Any
CPU" /t:Clean,Build /p:DeployOnBuild=true /p:DeployTarget=Package
/p:AutoParameterizationWebConfigConnectionStrings=false
I've tried to manually edit Reference elements in project files, adding <Private>True</Private>, with no success.
I am trying to work around this known issue, so that my second-level dependencies are automatically and correctly pulled into the web publishing temp directory.
My current attempt combines the general approach here (customizing the web publishing pipeline by adding a MyProject.wpp.targets file next to the web project file), combined with some MSBuild code for finding DLLs here. So far this has either produced no results or broken the project file. I am new to custom MSBuild code and find it pretty arcane.
My Question: I am looking for a more complete example that works in my specific case. I think the goal is to intervene in the web publishing pipeline that gathers files for copying to the package temp directory, and adding the second-level dependencies to it.
My custom MyWebProj.wpp.targets looks like this:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<BRPathFiles Include="$(SolutionDir)..\Common\**\*.dll;$(SolutionDir)**\*.dll" />
<ConfigPathFiles Include="$(SolutionDir)..\Common\**\*.config;$(SolutionDir)**\*.config" />
</ItemGroup>
<Target Name="CopySecondLevelDependencies" BeforeTargets="CopyAllFilesToSingleFolderForPackage">
<RemoveDuplicates Inputs="#(BRPathFiles->'%(RootDir)%(Directory)')">
<Output TaskParameter="Filtered" ItemName="BRPaths" />
</RemoveDuplicates>
<RemoveDuplicates Inputs="#(ConfigPathFiles->'%(RootDir)%(Directory)')">
<Output TaskParameter="Filtered" ItemName="ConfigPaths" />
</RemoveDuplicates>
<CreateItem Include="%(BRPaths.Identity);%(ConfigPaths.Identity);">
<Output ItemName="FileList" TaskParameter="Include"/>
</CreateItem>
<CreateItem Value="#(BRSearchPath);$(ConfigSearchPath)">
<Output TaskParameter="Value" PropertyName="SecondLevelFiles" />
</CreateItem>
</Target>
<ItemGroup>
<FilesForPackagingFromProject
Include="%(SecondLevelFiles->'$(OutDir)%(FileName)%(Extension)')">
<DestinationRelativePath>$(_PackageTempDir)\bin\%(FileName)%(Extension) </DestinationRelativePath>
<FromTarget>CopySecondLevelDependencies</FromTarget>
<Category>Run</Category>
</FilesForPackagingFromProject>
</ItemGroup>
</Project>
Assuming you have collected all libraries needed at runtime in a folder outside your solution/project, have you tried just using post-build events to copy all these libraries to your main project target directory (bin) and then include that directory in your deployment package using Sayeds method: http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx (also available in this post: How do you include additional files using VS2010 web deployment packages?)?
I have (among others) the following line in my main project's post-build events:
xcopy "$(ProjectDir)..\..\Libraries\*.dll" "$(TargetDir)" /Y /S
In addition to this, I have added the following lines to my .csproj file:
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
PostBuildLibraries;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="PostBuildLibraries">
<ItemGroup>
<_PostBuildLibraries Include="$(TargetDir)**\*" />
<FilesForPackagingFromProject Include="%(_PostBuildLibraries.Identity)">
<DestinationRelativePath>$(OutDir)%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
Be sure to add these lines after the import of the "Microsoft.WebApplication.targets". Check out the links above for more details.
This makes all the desired libraries available after each build (copied to the project's target directory) and each time I create a deployment package (copied to the obj\<CONFIGURATION>\Package\PackageTmp\bin).
Also, since I'm building my main project, not my solution, I'm using the $(ProjectDir) macro instead of the $(SolutionDir).